Spring-aop: Error Cannot convert value of type [$Proxy...] to required type
来源:互联网 发布:知行论坛注册 编辑:程序博客网 时间:2024/05/18 22:12
配置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 foundat 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 moreCaused 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 foundat 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.
- Spring-aop: Error Cannot convert value of type [$Proxy...] to required type
- Spring: Error Cannot convert value of type [$Proxy...] to required type
- 配置Spring Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource]
- java.lang.IllegalArgumentException: Cannot convert value of type [] to required type [] for property
- java.lang.IllegalArgumentException: Cannot convert value of type [] to required type [] for propert
- spring 事务异常Failed to convert property value of type [$Proxy12] to required type
- spring Failed to convert property value of type [$Proxy10] to required type
- spring启动报错:Cannot convert value of type [org.apache.commons.collections.map.LinkedMap] to required t
- Cannot convert value of type [java.lang.String] to required type [javax.sql.DataSource] for property 'dataSource': no matching e
- Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'xxx'
- Cannot convert value of type [java.lang.String] to required type [java.util.Date] for property 'xxx'
- mybatis 5.0 报错 Cannot convert value of type ‘com.github.pagehelper.PageHelper’ to required type ‘org
- spring Failed to convert property value of type 'java.lang.String' to required type 'int' for proper
- spring mvc 数据绑定报错 Failed to convert property value of type 'java.lang.String' to required type 'int'
- Failed to convert property value of type [$Proxy13] to required type
- Failed to convert property value of type [java.lang.String] to required type [boolean] for property
- SSH 项目异常:Failed to convert property value of type [$Proxy13] to required type
- Failed to convert value of type 'java.lang.String' to required type 'org.springframework.web.multipa
- iPhone UITableViewCell 表格单元格类型
- Android SfFlinger中的工作线程:threadLoop()
- 一个很恶心的打电话程序
- HP笔记本 no bootable device insert boot disk and press any key
- Effective C++和More Effective C++
- Spring-aop: Error Cannot convert value of type [$Proxy...] to required type
- SAP-BAPI-将指定的交货单发货过账(指定账期和出货仓位)
- 安装MySQL
- SimpleCursorAdapter 的使用
- Windows Phone7退出对话框的一点心得
- 斯特灵数
- 多线程死锁的解决之道
- ubuntu下安装极点五笔的方法
- 浅谈VB程序的破解