Over a million developers have joined DZone.

Turn a Java annotation into a CDI qualifier

· Java Zone

Discover how powerful static code analysis and ergonomic design make development not only productive but also an enjoyable experience, brought to you in partnership with JetBrains

A CDI qualifier is an annotation that itself is annotated with the @javax.inject.Qualifier meta-annotation. Per example, if you add the @Qualifier to the MyAnnotation (http://e-blog-java.blogspot.com/2011/04/what-is-java-annotation.html) you obtain a CDI qualifier:

@Qualifier
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation
{
// Property Definitions here.
}

CDI provide a set of built-in qualifiers:

Qualifier                         
 
 
Description
 
@javax.enterprise.inject.Named 
 
This qualifier is used to un-typed access from
non-Java code. Commonly this qualifier serves the
JSF pages that access beans through EL.
 
@javax.enterprise.inject.New 
 
This qualifier forces the creation of a new
instance, instead of using the contextual
instance. It allows us to obtain a dependent
object of a specified class.
 

@javax.enterprise.inject.Any
 
This qualifier “belongs” to all beans and 
injection points (not applicable when @New is
present). This is useful if you want to iterate
over all beans with a certain bean type.
 
@javax.enterprise.inject.Default
 
As the qualifier name suggests, whenever a bean
or injection point does not explicitly declare a
qualifier, the container assumes the qualifier
@Default.

 

From http://e-blog-java.blogspot.com/2011/04/turn-java-annotation-into-cdi-qualifier.html

Learn more about Kotlin, a new programming language designed to solve problems that software developers face every day brought to you in partnership with JetBrains.

Topics:

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}