I'm experimenting with AspectJ Load-time Weaving in Spring as described here. I've checked out the sample code, and it works as advertised.
But when I try to change the pointcut of the PerformanceAdvice from execution(..)
to call(..)
semantics, the advice no longer gets executed.
I know that Spring AOP does not support call(..)
semantics, but that should not apply here since I'm using AspectJ LTW (the sample code successfully works with non-Spring-managed objects).
Can anyone shed some light?
Update: In order to confirm that LTW works, I added the following system properties to the argline configuration in pom.xml:
-Dorg.aspectj.weaver.showWeaveInfo=true
-Daj.weaving.verbose=true
-Dorg.aspectj.tracing.enabled=true
-Dorg.aspectj.tracing.factory=default
-Dorg.aspectj.tracing.file=/tmp/aspectj-trace.txt
Now the output of running mvn test
contains the following lines:
[AppClassLoader] info AspectJ Weaver Version 1.5.3 built on Wednesday Nov 22, 2006 at 11:18:15 GMT
[AppClassLoader] info register classloader sun.misc.Launcher$AppClassLoader@5acac268
[AppClassLoader] info using configuration
/private/tmp/aspectj-load-time-weaving/target/test-classes/META-INF/aop.xml
[AppClassLoader] info register aspect org.springbyexample.aspectjLoadTimeWeaving.PerformanceAdvice
[AppClassLoader] weaveinfo Join point
'method-execution(void org.springbyexample.aspectjLoadTimeWeaving.Processor.process())'
in Type 'org.springbyexample.aspectjLoadTimeWeaving.Processor' (Processor.java:38)
advised by around advice from
'org.springbyexample.aspectjLoadTimeWeaving.PerformanceAdvice' (PerformanceAdvice.java)
[AppClassLoader] weaveinfo Join point
'method-execution(void org.springbyexample.aspectjLoadTimeWeaving.
PerformanceAdvice.aspectjLoadTimeWeavingExamples())'
in Type 'org.springbyexample.aspectjLoadTimeWeaving.PerformanceAdvice' (PerformanceAdvice.java:37)
advised by around advice from
'org.springbyexample.aspectjLoadTimeWeaving.PerformanceAdvice' (PerformanceAdvice.java)
So it seems that AspectJ has picked up the PerformanceAdvice and found 2 join points to weave it in. But if I replace execution(..)
with call(..)
in the PerformanceAdvice's join point and run maven again, the output does not contain those last 2 lines, and the advice is not executed. The AspectJ trace contains lots of log statements, but I couldn't make much sense out of it. I scanned it for errors or warnings, but found none.
(I assume that I should be able to simply replace execution(..)
with call(..)
, because their syntax is described as execution(MethodPattern)
and call(MethodPattern)
respectively in the AspectJ programming guide).
I also tried using a more recent version of AspectJ (1.6.6), but to no avail.