Spring AOP: Point annotation point not causing recommendations for execution

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

Here is my aspect:

 @Aspect @Component public class ExampleAspect { @Pointcut("execution(* example.*.ws.*.*(..))") public void isWebService() {} @Pointcut("@annotation(example.common.ws.WsTransaction)") public void isAnnotated() {} @Before("isWebService() && isAnnotated()") public void before() { System.out.println("before called"); } } 

This is an example class in which I expect it to run:

 package example.common.ws; @Endpoint 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 use only isWebService() , it is called, but when I try to use it with isWebService() && isAnnotated() or just isAnnotated() , nothing happens.

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

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

Annotation retention policy is runtime.

Spring version 3.0.3.RELEASE

I am not sure what is wrong or what I can try to debug.

Update: Spring AOP doesn't seem to select @Endpoint annotated classes

Update 2: AopUtils.isAopProxy(this) and AopUtils.isCglibProxy(this) are false (even when using <aop:aspectj-autoproxy proxy-target-class="true"/> )

+4
source share
2 answers

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

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

+2
source

I suppose there might be some problem with pointcut declaration.

  @Pointcut("@annotation(example.common.ws.WsTransaction)") 

See this link for a possible solution.

0
source

Source: https://habr.com/ru/post/1385307/


All Articles