0
Spring AOP適用於通過接口公開的方法。 Spring AOP通過目標類提供代理選項@EnableAspectJAutoProxy(proxyTargetClass = true)使用Spring AOP進行嵌套方法調用proxyTargetClass = true
在這種情況下,目標類是代理,所以我假設它的所有方法 - public,protected和private。
interface ISample {
public method1();
}
class Sample implements ISample {
@LogMe
public method1() {
...
method2();
}
@LogMe
private method2() {
...
}
}
我在類路徑配置CGLIB庫,該配置類具有@EnableAspectJAutoProxy(proxyTargetClass =真),縱橫類有@Aspect和@Component。如果使用@LogMe註釋,則方面類將記錄所有方法調用。
問題是用這個設置method2()調用不會被記錄?如果代理人在目標課堂上,不應該這樣工作嗎?
CGLIB代理作品[子類](http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop-api .html#aop-api-proxying-class)目標。由於'method2()'具有'private'訪問修飾符,因此它不能被覆蓋,因此不能被代理;這是你觀察到的。此外,'method2()'是內聯調用的,而不是通過可以被攔截的spring管理bean調用的。 –
@ Bond-JavaBond謝謝!春季文檔的解釋清楚表明。有建議的鏈接,我可以參考加載時間使用spring編織aspectj?通過將EnableLoadTimeWeaving和EnableSpringConfigured添加到配置文件並使用spring-instruments jar啓動服務器,基本配置的編織似乎不起作用。一套工作步驟對參考很有幫助。 –
請編譯面臨的問題,因爲新的帖子/問題..將很樂意幫助:) –