这是在做AOP的时候的报的错!  如果把Aop的配置删除 就OK!!!
  <bean id="dao" class="com.Dao.imp.UserDao"/>    //数据访问层
  <bean id="services" class="com.services.UserServices">   //业务逻辑层
   <property name="userDao" ref="dao"/>
  </bean>   <!-- Aop -->
  <bean id="beforedao" class="com.Dao.imp.insertDao"/>  //初始化插入的类
   
   <aop:config >
    <aop:aspect ref="beforedao">
<aop:before method="before" pointcut="execution(public * com.Dao.imp..*.*())"/>
    </aop:aspect>
   </aop:config>测试类:ApplicationContext ctx=new ClassPathXmlApplicationContext("beans.xml");
UserServices us=(UserServices) ctx.getBean("services");
us.add();
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'services' defined in class path resource [beans.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy4 implementing com.I.Dao.UserI,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.Dao.imp.UserDao] for property 'userDao'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy4 implementing com.I.Dao.UserI,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.Dao.imp.UserDao] for property 'userDao': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
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:222)
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:728)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:380)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at Test_Com.test.test(test.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy4 implementing com.I.Dao.UserI,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.Dao.imp.UserDao] for property 'userDao'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy4 implementing com.I.Dao.UserI,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.Dao.imp.UserDao] for property 'userDao': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:391)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1289)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1250)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
... 38 more
Caused by: java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy4 implementing com.I.Dao.UserI,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.Dao.imp.UserDao] for property 'userDao': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:231)
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:386)
... 42 more

解决方案 »

  1.   

     我觉得应该是你在services中的dao属性的类型的问题 楼主大概用的不是接口吧 检查下是不是直接用的实现类引用, aop会产生代理对象,代理对象实现UserI,但却不是UserDao类型的 因此注入时产生类型不匹配的错误 即services中的属性应该是 UserI dao;  而不是 UserDao dao; 
      

  2.   

    UserDao 的类型 不对 你在检查你的.java文件和你的配置文件
      

  3.   

    spring和hibernate可能是.jar包冲突。
    检查下名为asm.jar的包。可能由于Spring中的“asm-2.2.3.jar”和Hibernate中的“asm.jar”包冲突。
      

  4.   

    com.Dao.imp.UserDao
    要有相应的接口,不然会spring产生不了代理类。
      

  5.   

     <bean id="services" class="com.services.UserServices"> //业务逻辑层
      <property name="userDao" ref="dao"/>
      </bean>
    注入属性时,属性要用你那个com.Dao.imp.UserDaosh实现的接口
      

  6.   

    <bean id="services" class="com.services.UserServices"> //业务逻辑层
      <property name="userDao" ref="dao"/>
      </bean>这里的class应该是实现的业务逻辑类而不是接口类
      

  7.   

    spring 是面向借口变成,dao,service,都应该提供相应的借口,lz可以自己做个简单的代理类测试,加深对面向接口的理解,
    报错的原因是类型转换错误。从spring中获取对象的类型应该为接口类型