美文网首页
解决IDEA报错Could not autowire. Ther

解决IDEA报错Could not autowire. Ther

作者: 九里 | 来源:发表于2019-07-26 14:54 被阅读0次

更新项目之后IDEA突然出现了这样的报错信息。显示Could not autowire. There is more than one bean of 'xxx' type。这个错误的意思是xxx类型有不止一个bean,但是这个错误不会影响项目运行,相当于一个warning。

image.png
导致这个错误的原因通常是注入的类型有其他的实现类,所以IDEA提示注入的时候会冲突。比如我的项目出现这个错误的原因是项目中新增了一个定制的插件,这个插件里重写了这个类。
因此出现这个问题的时候可以有两种办法解决。
1.给不同的实现标注名字
使用Qulifier注解标注
@Autowired
@Qualifier(name = 'testService1')
private TestService testService;

2.使用@Primary

@Component
@Primary
public class TestService{}

参考文章

  1. StackOverFlow: Could not autowire, there is more than one bean error

  2. CSDN: spring @Primary-在spring中的使用

相关文章

网友评论

      本文标题:解决IDEA报错Could not autowire. Ther

      本文链接:https://www.haomeiwen.com/subject/kfzrrctx.html