Announcement Announcement Module
No announcement yet.
Spring AOP: Annotation pointcut not causing advice to execute Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring AOP: Annotation pointcut not causing advice to execute

    I am using Spring AOP (with AspectJ annotation style support) and want to execute code if a method is annotated with a specific annotation (WsTransaction).

    Here is my aspect:

    public class ExampleAspect {
        @Pointcut("execution(* example.*.ws.*.*(..))")
        public void isWebService() {}
        public void isAnnotated() {}
        @Before("isWebService() && isAnnotated()")
        public void before() {
            System.out.println("before called");
    This is an example class where I expect it to run:

    public class SomeEndpoint {
        @WsTransaction() // I want advice to execute if this annotation present
        @PayloadRoot(localPart = "SomeRequest", namespace = "http://example/common/ws/")
        public SomeResponse methodToBeCalled(SomeRequest request) {
                // Do stuff
                return someResponse;
    When I change @Before to only use isWebService() it is called but when I try it with isWebService() && isAnnotated() or just isAnnotated() nothing seems to happen.

    I have <aop:aspectj-autoproxy/> in my Spring config.

    The endpoint is created by Spring (using component-scan).

    The annotation's retention policy is runtime.

    Spring version is 3.0.3.RELEASE

    I am not sure what is wrong or what I can try to debug. Any help will be appreciated.

  • #2
    Hard to understand



    • #3
      I have updated to spring-ws 2.0.3 and spring 3.0.6 but the problem persists.


      • #4
        Further info: AopUtils.isAopProxy(this) and AopUtils.isCglibProxy(this) both returns false.
        I've tried setting proxy-target-class="true" on aop:aspectj-autoproxy.


        • #5
          Figured it out:

          Firstly I had to use <aop:aspectj-autoproxy proxy-target-class="true"/> to use class-based (CGLIB) proxies (instead of Java interface-based proxies).

          Secondly (and this is where I got stuck) I had to specify the above in the contextConfigLocation of the servlet handling the SOAP requests (MessageDispatcherServlet) instead of the root application context.

          If someone could explain exactly why I would be grateful because beans specified in my root applicationContext are autowired on endpoints so I assume all the different config locations are "connected".