note: this annotation is @qualifier.
The article directories
What does @Qualifier mean?1. @autowired infuses resources from the Spring container, but if it is an interface and there are two implementation classes inside the interface, if we need to use the methods of the interface, the system will not identify which implementation class we are using to implement it
conclusion
What does @Qualifier mean?
The modifier self-understanding is a supplement to @autowired, why do I think it is a supplement?Since we all know that the annotation follows @autowired, For the sake of understanding, I will consider it as a supplement. The keynote will be set here, and then we will see what kind of supplement it is.
Ii. Specific instructions
1.@Autowired is an injection of resources from the Spring container, but if it is an interface with two implementation classes in it, the system will not recognize which implementation class we are using if we need to use the methods of the interface
code as follows (example) :
@Autowired
// @Qualifier("PersonSeriverImpl2")
private PersonSeriver personSeriver;
public void eats() {
personSeriver.eat();
}
Look @ the Qualifier (” PersonSeriverImpl2 “)
the
I am comments yet my PersonSeriver has two implementation class, then I now run the program will offer the following wrong
under Caused by: org. Springframework. Beans. Factory. NoUniqueBeanDefinitionException: No qualifying bean of type ‘com. Itheima. Seriver. PersonSeriver’ available: expected single matching bean but found 2: personSeriverImpl, personSeriverImpl2
translation probably mean:
caused by the following reasons: Org. Springframework. Beans. Factory. NoUniqueBeanDefinitionException: no type is’ com. Itheima. Seriver. PersonSeriver qualified Bean: ‘expectations with a single match Bean, but found the 2: personSeriverImpl, personSeriverImpl2
that is to say, now into two resources, with which the resources to achieve it?The error is then reported, which is when our @Qualifier is needed to resolve the problem
- go to your implementation class and add the name @service (” PersonSeriverImpl2 “) and get the annotation off the @qualifier (” PersonSeriverImpl2 “), which is the interface method that your method needs to call
well, we’ll run our program again and it’s OK
conclusion
here is a one-sentence summary of the @qualifier annotation :
needs to inject service in Controller so how does my server have two implementation classes to distinguish between the two impls, we need to apply the @qualifier annotation, which provides a way to resolve this conflict
Read More:
- 【Error】gRPC failure=Status{code=UNAVAILABLE, description=io exception, cause=io.netty.channel.
- non-member function ‘xxxx’ cannot have cv-qualifier
- Description of classifier index in Weka
- SSIS Exception: Failed to retrieve long data for column “TS_Description”
- Detailed explanation of Python__ new__() method
- HTTP error 401 and 403 detailed explanation and solution
- Photoshop CS6 detailed installation of graphic tutorial
- Description: Failed to decrypt protected XML node “DTS:Password” with error 0x8009000B “Key not valid for use in specified state
- Debug Assertion Failed! Detailed solution
- Python error: permissionerror: [errno 13] detailed explanation of permission denied solution
- Detailed explanation of UART, SPI and IIC and their differences and relations
- Windowserror: [error 183] error and in Python os.raname () detailed explanation
- Detailed explanation of yield in Python — the simplest and clearest explanation
- Mac boot boot the most detailed explanation, so that the automatic start of the program can not escape
- [Python] numpy library array splicing np.concatenate Detailed explanation and examples of official documents
- Detailed steps for installing Visual Studio 2010 + Intel parallel studio Xe 2013 and configuring mpich2
- Server error 500 detailed error
- MacOS adds code command to vs Code
- command/usr/bin/codesign failed with exit code 1- code sign error
- code is 143 Container exited with a non-zero exit code 143