Results 1 to 4 of 4

Thread: Access to annotation in @Around?

  1. #1
    Join Date
    Aug 2006
    Posts
    16

    Default 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. #2
    Join Date
    Aug 2006
    Posts
    16

    Default

    that should have read:

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


    Pat

  3. #3
    Join Date
    Aug 2004
    Location
    Berne, Switzerland
    Posts
    42

    Default

    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
    Guido Schmutz
    Principal Consultant, Trivadis Switzerland
    Email: guido.schmutz AT trivadis.com

  4. #4
    Join Date
    Aug 2006
    Posts
    16

    Default

    Upgrading to the Aspectj 1.5.2 libs solved the problem for me.

    thanks,
    Pat

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •