SpringBoot 开启AOP后 出现无法注入的问题
提示错误
org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type
或者
java.lang.ClassCastException: com.sun.proxy.$Proxy12 cannot be cast to cn.edu.nuc.SpringTest.service.impl.DemoServiceImpl
解决方案
在application.properties中添加配置
1 2 |
|
springboot使用aop拦截controller干一些事导致service@Autowired全部注入失败
springboot使用aop拦截controller干一些事导致controller里的service@Autowired全部注入失败,报空指针
先集成使用aop吧
1 2 3 4 |
|
properties修改
|
proxy-target-class属性值决定是基于接口的还是基于类的代理被创建。如果proxy-target-class 属性值被设置为true,那么基于类的代理将起作用(这时需要cglib库)。
如果proxy-target-class属值被设置为false或者这个属性被省略,那么标准的JDK 基于接口的代理将起作用。
这个aop只能适用于 protect 和public
把controller中的所有方法都改成public