Spring AOP 配置須要注意的問題,CGLIBhtml
在生成aop代理類的時候,報錯: Could not generate CGLIB subclass of class [class XXXX]: Common causes of this problem include using a final class or a non-visible class;java
後通過檢查, 原來在spring啓動aop的配置裏面是這樣寫的spring
1 <aop:aspectj-autoproxy proxy-target-class="true"/> 編程
2<tx:annotation-driven proxy-target-class="true" transaction-manager="txManager" />
這樣的狀況,Spring是採用CGLIB去代理,而採用此方式代理,是不能夠面向接口編程的,也就是說要代理的類不能夠實現接口,並且要想正常使用貌似還要加上一個默認構造函數.ide
因此,解決這個問題,用Spring默認的代理方式就能夠了,配置改爲函數
1 <aop:aspectj-autoproxy/>this
2<tx:annotation-driven transaction-manager="txManager" />
就OK了.
轉載自:http://www.2016k.com/programmer/java/spring/01-123.html代理