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
版权声明:本文标题:service层实现类serviceImpl单元测试,报错org.springframework.beans.factory.UnsatisfiedDependencyException,报代理错误 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1726605260a1077486.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论