Qualifiers
Qualifiers are required in some cases to resolve conflicts during dependency injection by identifying the correct bean with a qualified name. In the last section, we discussed injecting the dependencies. We injected defaultPreferredLanguage in the IdentityCreator class that was produced by the Producer function of the PreferredLanguageProducer class. If we want to inject another field of the same type, we then have a problem. If we have another function that produces a bean of the PreferredLanguage type, the CDI wouldn't know which one to consider and inject. In order to solve this, we can specify qualifiers, such as the @Named annotation.
@Named is a qualifier that is shipped by the CDI. It is annotated with @Qualifier and can ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access