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’
问题前的各项代码
配置文件
测试代码
事务类代码![在这里插入图片描述](https://img-blog.csdnimg.cn/16397f40a25e47058cbb7f9ea5b4bf50.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5LiA5Y-q5bCP54y05a2QX0pheQ==,size_20,color_FFFFFF,t_70,g_se,x_16)
解决问题
看文章发现配置文件中开启事物注解少加了proxy-target-class="true"
proxy-target-class属性值决定是基于接口的还是基于类的代理被创建。首先说明下proxy-target-class="true"和proxy-target-class="false"的区别,为true则是基于类的代理将起作用(需要cglib库),为false或者省略这个属性,则标准的JDK 基于接口的代理将起作用。