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基于子类的动态代理

本文标签: typeaopSpringproxy