Java EE 6 Deployment Flexibility with CDI and the @Alternative Annotation
CDI (Contexts and Dependency Injection) is an integral part Java EE 6. This powerful facility enables you to develop Java EE components with well-defined scopes that exist within the lifecycle of an application. CDI also allows you to inject Java EE components such as JSF managed beans.
In his JavaBoutique article Applying CDI and the @Alternative Annotation in Java EE 6 Applications, Anghel Leonard explains how to use the
@Alternative annotation to configure your application for different deployments. He writes:
With CDI support (@Alternative annotation), you can package multiple beans that have the same injection point without errors -- you can apply the @Alternative annotation to more than one bean and specify the bean you want to use in the CDI beans.xml configuration file.
Leonard demonstrates how to use CDI and the
@Alternative by walking through the development of a volleyball and tennis game. The application employs NetBeans 6.9, JDK 6 and GlassFish v3.
Read the full story at JavaBoutique:
Applying CDI and the @Alternative Annotation in Java EE 6 Applications