java使用Spring AOP proxyTargetClass=true进行嵌套方法调用
SpringAOP在通过接口公开的方法上运行良好。Spring AOP通过target class@enableSpectJautoproxy(proxyTargetClass=true)在代理上提供了一个选项
在本例中,目标类是代理,因此我假设它的所有方法-public、protected和private
interface ISample {
public method1();
}
class Sample implements ISample {
@LogMe
public method1() {
...
method2();
}
@LogMe
private method2() {
...
}
}
我在类路径中配置了cglib库,配置类有@enableSpectJautoproxy(proxyTargetClass=true),方面类有@aspect和@Component。如果用@LogMe注释,则方面类记录所有方法调用
问题是这个设置method2()调用没有被记录?如果代理在目标类上,这不行吗?
# 1 楼答案
CGLIB代理不适用于我的案例。但我使用了AspectJ加载时编织
线程中的更多详细信息 Spring AspectJ loadtimeweaving not invoked