我试图在使用AspectJ的加载时编织和基于Spring和基于注释的配置的私有方法之前执行代码,并且我正在努力找出为什么我的方面没有被调用。
我简单的方面如下:
@Aspect
public class LoggingAspect {
private static Logger log = LoggerFactory.getLogger(LoggingAspect.class);
@Before("execution(private * com.mycompany.MyServiceWithPrivateMethods.*(..))")
public void privateAspect() {
log.warn("#### Private method aspect invoked!");
}
}
在我的Spring类上还有@EnableLoadTimeWeaving
注释,在META/aop.xml中有如下内容:
<aspectj>
<weaver options="-verbose">
<!-- only weave classes in our application-specific packages -->
<include within="com.mycompany.*"/>
</weaver>
<aspects>
<!-- weave in just this aspect -->
<aspect name="com.mycompany.LoggingAspect"/>
</aspects>
</aspectj>
最后,我还将根据文档使用-javaagent:/path/to/spring-instrument.jar
选项启动我的应用程序。我的类路径(spring-aop
和aspectjweaver
)上也有所需的jars,这在Spring中也提到过。
这有可能吗?AspectJ文档中列出了一个“限制”,即Privileged aspects are not supported by the annotation style.
located 这里,但是Spring中的这旧帖子似乎表明这确实是可能的。
发布于 2014-04-27 20:46:46
我原以为它会起作用,但我也认为您必须将aspectjweaver.jar添加为javaagent。其中一个假设是错误的?
https://stackoverflow.com/questions/23327336
复制相似问题