admin管理员组

文章数量:1530078

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'com.microboy.demo.service.Impl.AreaServiceImplTest': Unsatisfied dependency expressed through field 'areaServiceImpl'; 


nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'areaServiceImpl' is expected to be of type 'com.microboy.demo.service.Impl.AreaServiceImpl' but was actually of type 'com.sun.proxy.$Proxy75'

 

这个错误的根本原因看最后,在使用annotation(注解)的方式注入spring的bean 时,spring采用代理的机制导致的

    方案一:由于AreaServiceImpl 是一个实现类,使用JDK的动态代理不能注入,jdk的动态代理不支持类的注入,只支持接口方式注入,如果确时不想用spring提供的动态代理,则此时可以选择用cglib代理解决。必须引入cglib的外部包

   方案二:JDK的动态代理需要的是接口方式注入,那就将上面的注入类型修改为接口如下

本文标签: 报错单元测试错误serviceImplService