A CDI stereotype allows us to create new annotations that bundle up several CDI annotations. For example, if we need to create several CDI named beans with a scope of session, we would have to use two annotations in each of these beans, namely @Named
and @SessionScoped
. Instead of having to add two annotations to each of our beans, we could create a stereotype and annotate our beans with it.
To create a CDI stereotype in NetBeans, we simply need to create a new file by selecting the Contexts and Dependency Injection category and the Stereotype file type.
Then, we need to enter a name and package for our new stereotype.
At this point, NetBeans generates the following code:
package com.ensode.cdiintro.stereotype; import static java.lang.annotation.ElementType.TYPE; import static java.lang.annotation.ElementType.FIELD; import static java.lang.annotation.ElementType.METHOD; import static java.lang.annotation.RetentionPolicy.RUNTIME; import java.lang.annotation.Retention; import java...