Spring AOP两个错误解决

in Default with 0 comment

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包太老了,换成最新版本即可解决. 下载地址

原文地址:https://www.cnblogs.com/Ravenzzz/p/11489698.html

Responses