我正在尝试使用 AspectJ 的加载时编织与 Spring-Boot 和基于注释的配置在私有(private)方法之前执行代码,并且我正在抓紧时间试图找出为什么我的方面没有被调用。
我的简单方面如下:
@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!");
}
}
我还有 @EnableLoadTimeWeaving
我的 Spring 配置类上的注释以及 META-INF/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
开始我的申请。选项,根据文档。我的类路径上也有所需的 jar( spring-aop
和 aspectjweaver
),正如 Spring 文档中提到的。
这可能吗? AspectJ 文档中列出了一个“限制”,指出 Privileged aspects are not supported by the annotation style.
位于here ,但是this Spring论坛中的旧帖子似乎表明这确实是可能的。
最佳答案
我本以为它会起作用,但我也认为你必须添加aspectjweaver.jar作为javaagent。这些假设之一是错误的?
关于java - 使用 Spring 和 AspectJ 拦截私有(private)方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23327336/