Java Reference
In-Depth Information
Chapter4.Learning Context and
Dependency Injection
We saw that
Chapter 3
,
Introducing Java EE 7 - EJBs
, was challenging since we had to
cover lots of ground, including Java Enterprise enhancements and a Maven-specific config-
uration. In this chapter, we'll discuss
Contexts and Dependency Injection
(
CDI
), which
was added to the Java EE specification in Java EE 6 (starting from JSR 299). It provides
several benefits to Java EE developers that were missing, such as allowing any JavaBean to
be used as a JSF managed bean, including stateless and stateful session beans. You can find
more information on CDI and the newest version of the specification itself (JSR 346) at
Some of the topics that will be covered in this chapter are as follows:
• What Contexts and Dependency Injection is and how it relates to EJB
• How to rewrite our ticket-booking example to use the CDI and JavaServer Faces
technology
• How to run the project using Maven
This chapter assumes familiarity with
JavaServer Faces
(
JSF
), which will be used to
provide a graphical interface for our applications. If you are looking for a start up guide for
JSF, there are several excellent resources available online, including the relevant sections in
the official Java EE 7 tutorial at
http://docs.oracle.com/javaee/7/tutorial/doc/jsf-devel-