您的位置:首页 > 编程语言 > Java开发

错误:Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'iCustome

2019-05-29 15:56 1646 查看
4000

Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named ’ iCustomerService ’ is expected to be of type ’ service.ICustomerServiceImpl ’ but was actually of type ‘com.sun.proxy.$Proxy13’

原因分析:
spring默认使用jdk方式创建代理对象,而不是cglib方式
二者区别主要在于,jdk方式只能代理接口实现类,cglib既可以代理接口实现类又可以代理一般类
ICustomerServiceImpl经过代理之后变成了iCustomerService接口类型

方案一:使用cglib代理方式,配置文件

<aop:config proxy-target-class=“true”>

方案二:使用接口类型调用方法

iCustomerService.service();

方案三:不做增强

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐