5 Replies Latest reply on Aug 12, 2009 1:07 PM by whitingjr

    JDK 5 annotated method pointcut

    kedzie

      I'm trying to make a pointcut which intercepts all methods which are annotated with a certain annotation. When I run the ant compiler it finds the my aspect, but when I processes the class which has an annotated method, it says "no pointcuts found". I use the same syntax as the documentation.

      @Target({ElementType.METHOD})
      public @interface MyAnnotation {}
      
      @Aspect(scope=Scope.PER_VM)
      public class MyAspect {
      
      @Bind(pointcut="execution(* *->@com.company.MyAnnotation(..))")
      public Object transaction(MethodInvocation invocation) throws Throwable {..}
      
      class SomeOtherClass {
      @MyAnnotation() public void foo() {..}
      }
      


      It should intercept every invocation to the method SomeOtherClass.foo(). But it is not binding the pointcut for some reason. Is my pointcut defintion correct? Thanks a lot.





        • 1. Re: JDK 5 annotated method pointcut
          flavia.rainone

          Hi!

          You need to configure the aoppath so that your annotated classes can be found by JBoss AOP.

          Take a look at the examples build script (at JBoss AOP dist, the script that is used to run the examples). There you will find an example of how aoppath is configured so that JBoss AOP finds your annotations.

          • 2. Re: JDK 5 annotated method pointcut
            kedzie

            I set the aoppath, and the aop compiler finds the Aspect class correctly. It is the pointcut that doesn't work. I get the same result when I use a jboss-aop.xml file instead of annotations to define the pointcut (pointcut still points to an annotated method). When I change the pointcut to a specific method or group of methods it works fine. I just can't get it to find annotated methods.

            • 3. Re: JDK 5 annotated method pointcut
              whitingjr

              Hi,
              I also am trying to implement pointcuts using annotated methods. Also seeing the same problem of no aspect invocation.

              Jeremy

              • 4. Re: JDK 5 annotated method pointcut
                whitingjr

                BTW, the version of AOP I am using is 2.1.1.GA. The one bundled in AS 5.1.0.GA

                Jeremy

                • 5. Re: JDK 5 annotated method pointcut
                  whitingjr

                  Try setting the RetentionPolicy on your method annotation.

                  @Target({ElementType.METHOD})
                  @Retention(RetentionPolicy.RUNTIME)
                  public @interface MyAnnotation {}


                  This solved the problem for me.