0
点赞
收藏
分享

微信扫一扫

Spring中出现org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named ‘accountServic

酷子腿长一米八 2022-02-23 阅读 33

Spring5测试声明式事务管理(注解方式)出现的问题

org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named ‘accountServiceImpl’ is expected to be of type ‘com.itcast.service.impl.AccountServiceImpl’ but was actually of type 'com.sun.proxy.$Proxy18’

问题前的各项代码

配置文件

在这里插入图片描述

测试代码

在这里插入图片描述

事务类代码在这里插入图片描述

解决问题

看文章发现配置文件中开启事物注解少加了proxy-target-class="true"

proxy-target-class属性值决定是基于接口的还是基于类的代理被创建。首先说明下proxy-target-class="true"和proxy-target-class="false"的区别,为true则是基于类的代理将起作用(需要cglib库),为false或者省略这个属性,则标准的JDK 基于接口的代理将起作用。

配置文件

修改之前

在这里插入图片描述

修改之后

在这里插入图片描述

本人现在处于学习阶段,文章中有什么问题,请发私信告知我。感谢!
举报

相关推荐

0 条评论