Announcement Announcement Module
Collapse
No announcement yet.
Access to annotation in @Around? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Access to annotation in @Around?

    Is it possible to get access to the annotation used in an @Around pointcut? I would have expected this to work:

    @Around("@annotation("myAnnotation")
    public Object doSomething( ProceedingJoinPoint pjp, MyAnnotation myAnnotation ) { }

    I have used the @annotation(annotationname) syntax to access the annotation in other contexts. But when used in an @Around pointcut the ProceedingJoinPoint arg seems to break this. I have read the documentation and tried variations on argNames() and attempting to declare the joinpoint in the pointcut, but none of this works.

    Can someone tell me how to do the above?


    thanks,
    Pat Niemeyer

  • #2
    that should have read:

    @Around( "@annotation(myAnnotation)" )
    public Object doSomething(
    ProceedingJoinPoint pjp, MyAnnotation myAnnotation ) { }


    Pat

    Comment


    • #3
      Hi

      Just did some tests, it worked fine for me with LTW, but if I use plain Spring AOP, then I had some troubles as well.

      At the end, I found that the reason is the AspectJ libraries, it only works with 1.5.2, but Spring 2.0rc2 includes the 1.5.1a.

      After upgrading to the 1.5.2, the following sample works fine for me

      Code:
      @Around("execution(* *.*(..)) && @annotation(test)")
      public Object testdata(ProceedingJoinPoint jp, TestAnnotation test) throws Throwable {
      	System.out.println("before .... " + test.name());
      	jp.proceed();
      	System.out.println("after .... " + test.name());
      		
      	return null;
      }
      	
      @Before("execution(* *.*(..)) && @annotation(TestAnnotation)")
      public void testBefore() {
      	System.out.println("before");
      }
      	
      @Before("execution(* *.*(..)) && @annotation(test)")
      public void testBefore(TestAnnotation test) {
      	System.out.println("before2" + test.name());
      }
      Just tested a few different version, not very meaningful I agree ;-)

      You also need the aspectj-autoproxy in the Spring context

      Code:
      	<aop:aspectj-autoproxy />
      Hope this works for you as well.

      Guido

      Comment


      • #4
        Upgrading to the Aspectj 1.5.2 libs solved the problem for me.

        thanks,
        Pat

        Comment

        Working...
        X