1.报错内容
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'userDao' is expected to be of type 'com.yg.dao.impl.UserDaoImpl' but was actually of type 'com.sun.proxy.$Proxy20'
at org.springframework.beans.factory.support.AbstractBeanFactory.adaptBeanInstance(AbstractBeanFactory.java:417)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:398)
2.解决方法
<aop:aspectj-autoproxy proxy-target-class="true"/>
3.proxy-target-class参数解释
- 默认 proxy-target-class = false,即 implements InvocationHandler
- proxy-target-class=true:基于类的代理将起作用(这时需要cglib库) implements MethodInterceptor
- proxy-target-class=false: 基于标准的JDK 基于接口的代理 implements InvocationHandler
。