# The Java EE 7 Tutorial

# 23 Introduction to Contexts and Dependency Injection for Java EE

Contexts and Dependency Injection for Java EE (CDI) is one of several Java EE features that help to knit together the web tier and the transactional tier of the Java EE platform. CDI is a set of services that, used together, make it easy for developers to use enterprise beans along with JavaServer Faces technology in web applications. Designed for use with stateful objects, CDI also has many broader uses, allowing developers a great deal of flexibility to integrate various kinds of components in a loosely coupled but typesafe way.

CDI 1.1 is specified by JSR 346. Related specifications that CDI uses include the following:

- JSR 330, Dependency Injection for Java

- The Managed Beans specification, an offshoot of the Java EE 7 platform specification (JSR 342)

The following topics are addressed here:

- Getting Started

- Overview of CDI

- About Beans

- About CDI Managed Beans

- Beans as Injectable Objects

- Using Qualifiers

- Injecting Beans

- Using Scopes

- Giving Beans EL Names

- Adding Setter and Getter Methods

- Using a Managed Bean in a Facelets Page

- Injecting Objects by Using Producer Methods

- Configuring a CDI Application

- Using the @PostConstruct and @PreDestroy Annotations with CDI Managed Bean Classes

- Further Information about CDI