The usage of @Qualifier is quite simple, although people not always get it right. Lets quickly recap when to use and when it is unnecessary.
Single Candidate
If you are trying to inject a Bean and you only have a single candidate of that type on your Spring Application Context, then there is no need for any @Qualifier. Spring can determine which Bean to use, as there is a single candidate:
//DON'T
@Autowired
@Qualifier("someClass") //Unnecessary as there is a single candidate
private SomeClass someClass;
//DO
@Autowired
private SomeClass someClass; //Works as there is a single candidate
Note that this would work even if the name of the property differed:
//DO
@Autowired
private SomeClass xpto; //Works as there is a single candidate
Multiple Candidates
If you are trying to inject a Bean and you have multiple candidates of that type on your Spring Application Context, then Spring needs to be able to disambiguate which one to use.
Sometimes it can do it implicitly. It is the case of when your property name matches exactly the name of one of the beans:
//DO
@Autowired
private SomeClass someClass; //Works implicitly
But it would fail if the name differed:
//DON'T
@Autowired
private SomeClass xpto; //This will fail as there are several candidates
In this case you would have to add a @Qualifier to explicitly state the name of the Bean to pick:
//DO
@Autowired
@Qualifier("someClass") //Works as we disambiguated the name to pick
private SomeClass xpto;





[…] a previous post we revised how to use @Qualifier and how it allows you to disambiguate what Bean to inject, when […]