admin管理员组文章数量:1567036
现象
运行Spring Web程序时报出错误
BeanNotOfRequiredTypeException: Bean named ‘loginLogService’ is expected to be of type ‘com.qst.service.LoginLogServiceImpl’ but was actually of type ‘com.sun.proxy.$Proxy28’
原因
图中这里直接写的是实现类而不是接口。另一方面
<tx:annotation-driven proxy-target-class=“false” transaction-manager=“transactionManager” />
proxy-target-class=“false” 意味着Spring使用JDK自带的动态代理实现AOP。这样由于JDK动态代理所代理的目标必须是接口,而这里却是一个普通类,所以就抛出此异常。
解决办法
1、 将图中的具体实现类改成接口,这样即使使用JDK动态代理也能实现。
2、proxy-target-class=“true” 使用CGLIG动态代理,这样就可以直接代理普通类。
总结
关于proxy-target-class="true"问题,请参考链接:
Spring: proxy-target-class 决定 用 CGlib 还是 JDK AOP 来生成代理
本文标签: xxxexpectedbeannamedproxy
版权声明:本文标题:Bean named XXX is expected to be of type XXX but was actually of type 'com.sun.proxy.$Proxy28' 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1726602665a1077220.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论