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"/>
)
source share