更新項目之后IDEA突然出現了這樣的報錯信息。顯示Could not autowire. There is more than one bean of 'xxx' type
。這個錯誤的意思是xxx類型有不止一個bean,但是這個錯誤不會影響項目運行,相當於一個warning。
導致這個錯誤的原因通常是注入的類型有其他的實現類,所以IDEA提示注入的時候會沖突。比如我的項目出現這個錯誤的原因是項目中新增了一個定制的插件,這個插件里重寫了這個類。
因此出現這個問題的時候可以有兩種辦法解決。
1.給不同的實現標注名字
使用Qulifier注解標注
@Autowired
@Qualifier(name = 'testService1')
private TestService testService;
2.使用@Primary
@Component
@Primary
public class TestService{}