Enterprise Tech Tip: Using CDI and Dependency Injection for Java in a JSF 2.0 Application
By edort on Oct 30, 2009
The next release of the enterprise Java platform, Java EE 6 includes a number of powerful new technologies and well as significant enhancements to existing technologies. Two of the new technologies are JSR 299: Contexts and Dependency Injection (CDI) (referred to in earlier times as Web Beans) and JSR 330: Dependency Injection For Java. One of the significantly enhanced technologies is JSR 314: JavaServer Faces 2.0.
CDI defines a set of services for the Java EE environment that makes applications much easier to develop. Perhaps most significantly, CDI unifies and simplifies the Enterprise JavaBeans (EJB) and JavaServer Faces (JSF) programming models. It allows enterprise beans to act as managed beans in a JSF application.
Until now there has not been a standard approach for annotation-based dependency injection. Dependency Injection For Java changes that by introducing a standard set of annotations that can be used for dependency injection.
If you're involved with creating user interfaces (UIs) for web applications, you're probably familiar with JavaServer Faces. It's a technology that provides a server-side component framework that is designed to simplify the development of UIs for Java EE applications. The latest release of the technology, JSR 314: JavaServer Faces 2.0, makes UI development for Java EE applications even easier through support for annotations and the addition of new features such as Facelets and composite components.
You can get a good idea of how these technologies simplify web application development by reading the Tech Tip Using CDI and Dependency Injection for Java in a JSF 2.0 Application, written by Roger Kitain, the JavaServer Faces co-specification lead. Roger presents a JSF 2.0 application and shows in the source code where CDI components and Dependency Injection for Java annotations play a role.