其他分享
首页 > 其他分享> > expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} 注入失败,解决方案

expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} 注入失败,解决方案

作者:互联网

把@Autowired 改成以下:

@Autowired(required = false)

@Autowired(required=false):表示忽略当前要注入的bean,如果有直接注入,没有跳过,不会报错。

在容器的启动过程中,会初始化很多bean,这也是spring的核心之一(IOC)。但是在注入的过程中,扫描到公共方法中要注入的bean,并未找到,强行注入就会注入失败。我们又不能单独的去除改方法,所以我们采取的思想就是有bean就注入,没有就不注入。

标签:qualifies,autowire,candidate,Autowired,required,bean,报错,false,注入
来源: https://www.cnblogs.com/DanielL916/p/16477408.html