配置aop:config事务管理时,出现异常
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy8 implementing com...base.dao.IEntityDao,org.springframework.beans.factory.InitializingBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised' to required type 'com...springsecurity.users.service.UserService' for property 'userService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy8 implementing com...base.dao.IEntityDao,org.springframework.beans.factory.InitializingBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com...springsecurity.users.service.UserService] for property 'userService': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:462)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:499)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:493)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1371)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1330)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
... 62 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type [$Proxy8 implementing com...base.dao.IEntityDao,org.springframework.beans.factory.InitializingBean,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com...springsecurity.users.service.UserService] for property 'userService': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:231)
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:447)
... 68 more
Google到解决方法一:http://www.bitsandpix.com/entry/spring-error-cannot-convert-value-of-type-proxy-to-required-type/
Spring: Error Cannot convert value of type [$Proxy...] to required type
March 22nd, 2009 by jeremychone
In Spring, if you get an error like:
Error Cannot convert value of type [$Proxy...] to required type
It might be because you are using Spring AOP (e.g., @transactional annotations) with “interface-proxy” mode (the Default) rather than “class-proxy” mode. To setup “class-proxy” do the following:
- Copy aspectjweaver.jar and aspectjrt.jar to your Web application classpath (you can find these files in the Spring Distribution/lib/aspectj
- Add the following in the your app context xml:
<aop:config proxy-target-class=”true”/>
See also:
- Spring Forum: Spring Proxy exception
Google到解决方法二:http://forum.springsource.org/showthread.php?52092-Cannot-convert-value-of-Type-Proxy8
problem solved
I had the same issue, and been battling it for a while only to discover this:
Your Service class
must implement an interface, so if you already don't have, you 'll need to create an interface for your class. Then in the Unit Test class, you must declare the interface as a bean property rather than the concrete implementation of it. And finally assuming that your unit test (which is using AbstractAnnotationAwareTransactionalTests) constructor has:
setDependencyCheck(false);
setAutowireMode(AUTOWIRE_BY_NAME);
The automatic wiring should work, and you shouldn't get any dependency or type related errors.
It appears the AbstractAnnotationAwareTransactionalTests requires the property bean to use Interface pattern rather than direct class when your Service class uses other base service super class... etc
Google到解决方法三:http://forum.springsource.org/showthread.php?65802-Spring-Proxy-exception-Proxy13
I suggest you read chapter 6 of the reference guide, that explains how spring utilizes AOP. Spring uses a proxy based approach and by default it uses a proxy based approach based on interfaces.
There is a dynamic class created which implements Serializable and Runnable (the 2 interfaces you implements) to the dynamic class is a Runnable and Serializable it is NOT a DoStuff class anymore (as the classcast already suggests).
You have 3 choices
1) Cast to a Runnable instead of a DoStuff (the executor service needs a runnable(
2) Switch to class proxing (chapter 6 explains this)
3) Make DoStuff an interface and your class DoStuffImpl that way DoStuff will be part of the list of interfaces implemented by the dynamic proxy.