@Detailed description and code demonstration of qualifier

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: