admin管理员组文章数量:1530232
报错异常
org.springframework.beans.factory.BeanNotOfRequiredTypeException:
Bean named ‘accountService’ is expected to be of type ‘com.itheima.service.impl.AccountServiceImpl’ but was actually of type ‘com.sun.proxy.$Proxy34’
报错代码:
方法一、
将红色圈住的AccountServiceImpl.class实现类换成IAccountService.class接口
你可能很奇怪,我明明在SpringIOC容器中注册的是实现类的Bean对象,为什么我取出来
时指定的类型确实接口类型呢?其实我也不太懂。
我只知道此时采用了AOP关联了这个AccountServiceImpl实现类,Spring AOP自动对这个
实现类的接口做了动态代理,所以你取出来时必须用接口类型来承载
方法二、
在这个位置加上:
<aop:aspectj-autoproxy proxy-target-class="true"/>
网上说这个语句作用是开启cglib基于子类的动态代理
版权声明:本文标题:Spring AOP ××× but was actually of type com.sun.proxy.Proxy 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://m.elefans.com/dianzi/1726602100a1077153.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论