Spring AOP兩個錯誤解決


 

1.Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sword' defined in class path resource [Demo/applicationContext.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException:

#問題解決:缺少了 aspectjweaver.jar 包,下載地址

#順便附上另一個有可能缺少的包:aopalliance-1.0.jar,下載地址

 

2.Exception in thread "main" java.lang.ClassCastException: class com.sun.proxy.$Proxy11 cannot be cast to class XXX

(com.sun.proxy.$Proxy11 and Demo.BraveKnight are in unnamed module of loader 'app')

 

#報錯信息:動態代理生成的類無法轉換到我們自定義的實現類

#問題解決:在aop:config標簽中添加 proxy-target-class="true" 即可。

 

3.<aop:aspectj-autoproxy /> 引起UnsatisfiedDependencyException問題解決;

#解決方法:aspectjweaver包太老了,換成最新版本即可解決. 下載地址

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM