问题描述
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testDao' defined in class path resource [dao-beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy4] to required type [com.zl.dao.impl.BaseDaoImpl] for property 'baseDao'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy4] to required type [com.zl.dao.impl.BaseDaoImpl] for property 'baseDao': no matching editors or conversion strategy foundat org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:478)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)at java.security.AccessController.doPrivileged(Native Method)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:220)at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:429)at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:729)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:381)at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)at com.zl.test.SpringTest.runTest(SpringTest.java:20)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)at java.lang.reflect.Method.invoke(Unknown Source)at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:66)at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy4] to required type [com.zl.dao.impl.BaseDaoImpl] for property 'baseDao'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy4] to required type [com.zl.dao.impl.BaseDaoImpl] for property 'baseDao': no matching editors or conversion strategy foundat org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:391)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1287)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1248)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1008)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:470)... 34 moreCaused by: java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy4] to required type [com.zl.dao.impl.BaseDaoImpl] for property 'baseDao': no matching editors or conversion strategy foundat org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:219)at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)... 38 more 问题补充:morgan117 写道
解决方案
最好还有com.zl.dao.impl.TestBeanDaoImpl这个类的代码,只要把属性贴出来就行
解决方案二:
你有设置自动代理baseDao这个类吗?又没有用到BeanNameAutoProxyCreator或者DefaultAdvisorAutoProxyCreator类呢?
解决方案三:
你把实例化这个bean的代码贴出来看
解决方案四:
baseDao这个属性,你传进去的是baseDao的代理类,自然不能转化为BaseDao类的。