spring aop报错:Cannot proxy target class because CGLIB2 is not available.
今天在通过SApring AOP实现log4j时遇到问题:
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy7 implementing com.passing.spring.service.SearchEnToCn,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'com.passing.spring.service.impl.SearchEnToCnBean' for property 'searchEnToCnBean'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy7 implementing com.passing.spring.service.SearchEnToCn,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.passing.spring.service.impl.SearchEnToCnBean] for property 'searchEnToCnBean': no matching editors or conversion strategy found
网上搜了一下,结合了不同的解决方法后总结了一下
解决方法:
com.ideal.service.impl.UserServiceImpl实现的是com.ideal.service.interfaces.UserService接口,由于spring实现的是接口注入,关联的实现类。这里实现注入类,所以出现了异常。
在spring配置文件加入以下代码,实现类注入
<aop:config proxy-target-class="true"></aop:config>
之后又遇到问题:
Caused by: org.springframework.aop.framework.AopConfigException: Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.
解决方法:
导入cglib-nodep-2.1_3.jar包(不能是cglib-nodep-2.2.jar,或者导入asm-2.2.3.jar和cglib-2.2.jar )
OK,问题解决
对了,我用的是spring3.0.1