我正在试验
Spring中的AspectJ加载时编织,如
here所述.我已经检查了
sample code,它的工作方式与广告一样.
但是当我尝试将PerformanceAdvice的切入点从执行(..)更改为调用(..)语义时,建议不再被执行.
我知道Spring AOP不支持call(..)语义,但这不应该适用于此,因为我使用的是AspectJ LTW(示例代码成功地与非Spring管理的对象一起使用).
任何人都能解释一下吗?
更新:
为了确认LTW的工作原理,我在argline配置中添加了以下系统属性
pom.xml中:
> -Dorg.aspectj.weaver.showWeaveInfo = true
> -Daj.weaving.verbose = true
> -Dorg.aspectj.tracing.enabled = true
> -Dorg.aspectj.tracing.factory =默认
> -Dorg.aspectj.tracing.file = / tmp / aspectj-trace.txt
现在运行mvn test的输出包含以下行:
[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)
因此看起来AspectJ已经选择了PerformanceAdvice并找到了2个连接点来编织它.但是如果我在PerformanceAdvice的连接点中使用call(..)替换执行(..)并再次运行maven,则输出不包含最后两行,并没有执行建议. AspectJ跟踪包含许多日志语句,但我无法理解它.我扫描了它是否有错误或警告,但没有找到.
(我假设我应该能够简单地用call(..)替换execute(..),因为它们的语法在AspectJ programming guide中分别被描述为execute(MethodPattern)和call(MethodPattern).
我也尝试使用更新版本的AspectJ(1.6.6),但无济于事.
最佳答案 呼叫指示符应该与您的切入点一起使用.
你的调用类是否在weaver元素中指定的包中?
<weaver>
<!-- only weave classes in this package -->
<include within="org.springbyexample.aspectjLoadTimeWeaving.*" />
</weaver>
如果调用和执行类在不同的包中并且它与执行一起工作,那么修复aop.xml文件或将您的调用类重构为在给定的包中.