Learn about Contexts and Dependency Injection (CDI)

Contexts and dependency injection (CDI) for the Java™ EE platform is an implementation based on the JSR 346 specification. You can create applications that implement CDI in your Java EE projects.

Overview

CDI 1.0 applications are activated by the presence of a beans.xml file that exists in the WEB-INF directory of a web archive (WAR), or in the META-INF directory of other types of archives, as defined by the JSR 299 specification.

Starting with CDI 1.1 (JSR 346), the presence of a beans.xml file is no longer required if bean defining annotations are specified. For more information about bean defining annotations, see the CDI 1.2 specification, or CDI 2.0 specification. You can use CDI 1.2 with WebSphere Application Server Liberty and traditional, and CDI 2.0 with WebSphere Application Server Liberty.

When activated, the container provides services such as:
  • Context management
  • Type-safe dependency injection: A CDI-managed bean is instantiated and injected as needed.
  • Decorators, which implement one or more bean interfaces and can contain business logic. Decorators are disabled by default. You can have multiple decorators per bean and order is defined by the beans.
  • Interceptor bindings. Interceptors, which are enabled manually in the beans.xml file, are bound by using an interceptor binding type.
  • Event model
  • Integration into JavaServer Faces (JSF) and JavaServer Pages (JSP) files by using the Expression Language (EL)

Validation for CDI applications

Your workspace provides in-line and quick-fix validations for contexts and dependency injection applications. In CDI-faceted projects, as-you-type validation is supported.

Starting with CDI 1.1, session beans or managed beans that are annotated with @Vetoed are considered disabled, and are not validated.

For more information about the CDI annotations, see the Oracle Java EE API documentation.

For more information about using CDI in WebSphere® Application Server traditional, see Contexts and Dependency Injection (CDI).