spring-boot 启动时候 出现异常:The bean 'xxx' could not be injected as a 'xx.xxxx' because it

Posted Romic的博客园

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring-boot 启动时候 出现异常:The bean 'xxx' could not be injected as a 'xx.xxxx' because it相关的知识,希望对你有一定的参考价值。

The bean ‘xxxService‘ could not be injected as a ‘AaaXxxService‘ because it is a JDK dynamic proxy that implements: 


Action:  
  
Consider injecting the bean as one of its interfaces or forcing the use of CGLib-based proxies by setting proxyTargetClass=true on @EnableAsync and/or @EnableCaching.

查了半天,原来是因为把 @Autowired 换成了 @Resource

以前的代码是

@Autowired
private AaaXxxService xxxService;

修改后的代码

@Resource
private AaaXxxService xxxService;

这样就报错了。。

主要问题是名字和类名不一样导致 Resource 注入失败,但是刚好又有一个 xxxService 同名的类存在,就会报这个错误

解决方法就是 名字改成和类一样

@Resource
private AaaXxxService aaaXxxService;

 

以上是关于spring-boot 启动时候 出现异常:The bean 'xxx' could not be injected as a 'xx.xxxx' because it的主要内容,如果未能解决你的问题,请参考以下文章

spring-boot实战07:Spring Boot中Web应用的统一异常处理

在春季批处理(spring-boot-1.5.2.RELEASE)中使用多个数据源在启动时引发异常

Spring-Boot启动异常NoClassDefFoundError: javax/servlet/Servlet

求助,spring-boot升级带来的异常

what's the python之异常处理

解决spring-boot启动异常Unable to start EmbeddedWebApplicationContext due to missing EmbeddedServletContain