解决IDEA报错Could not autowire. There is more than one bean of 'xxx' type

After updating the project IDEA suddenly appeared in this error message. Display Could not autowire. There is more than one bean of 'xxx' type. This error means that xxx have more than one type of bean, but this error does not affect the operation of the project, the equivalent of a warning.


The reason for this error is usually injected into other types of implementation class, so when injected IDEA prompt conflict. For example, I project the emergence of this error because the project added a custom built-ins, the plug-in to rewrite this class.
Therefore, this problem occurs when there are two solutions.
1. to achieve a different label names
using Qulifier comment marked

@Autowired
@Qualifier(name = 'testService1')
private TestService testService;

2. Use @Primary

@Component
@Primary
public class TestService{}

Reference article

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

  2. CSDN: spring @ Primary- use in the spring of

Guess you like

Origin www.cnblogs.com/rever/p/11250396.html