Qualifiers
A qualifier is an annotation that has @Qualifier
declared on it, which signifies to the container that this qualifier annotation can be utilized on injection points and beans to distinguish different implementations of the same bean type.
A qualifier annotation, without any members, is just:
@Qualifier @Retention(RUNTIME) @Target( { TYPE, METHOD, FIELD, PARAMETER } ) public @interface MyQualifier {}
Note
@MyQualifier
has been defined for use on a Java type, method, field, or method parameter.
We can use field injection with @MyQualifier
by:
@Inject @MyQualifier private Locale myLocale;
Or constructor injection:
@Inject public Notifications(@MyQualifier Locale myLocale) { this.myLocale = myLocale; }
Or an initializer method:
@Inject public void ...
Get JBoss Weld CDI for Java Platform now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.