Contexts & Dependency Injection for Java

CDI 1.1 & 1.2

CDI 1.1 focuses on improving CDI 1.0 and CDI 1.2 is a minor update correcting issues in 1.1:

  • Add global enablement of interceptors (see the Java Interceptors Specification 1.2), global enablement of decorators (read more) and alternatives (read more) using the @Priority annotation
  • Add support for @AroundConstruct lifecycle callback for constructors (see the Java Interceptors Specification 1.2)
  • Allow binding interceptors to constructors
  • Moved interceptor binding to interceptors spec, allowing for reuse by other specifications
  • Support decorators on built in beans (read more)
  • Add EventMetadata (read more) to allow inspection of event metadata
  • Add @Vetoed annotation allowing easy programmatic disablement of classes (read more)
  • Many improvements for passivation capable beans, including @TransientReference allowing instances to be retained only for use within the invoked method or constructor (read more and read more)
  • Add scope activation and destruction callback events (read more)
  • Add AlterableContext allowing bean instances to be explicitly destroyed (read more)
  • Add automatic enablement of CDI for beans with a scope annotation, and EJBs, in Java EE (read more)
  • Add class exclusion filters to beans.xml to prevent scanning of classes and packages (read more)
  • Add Unmanaged allowing easy access to non-contexutal instances of beans (read more)
  • Add CDI allowing easy accesss to the current CDI container (read more)
  • Add AfterTypeDiscovery event, allowing extensions to register additional types after type discovery (read more)
  • Add @WithAnnotations as a way of improving extension loading performance (read more)
  • Many minor improvements to portable extensions (read more)

CDI 3.0

CDI 3.0 is part of Jakarta EE 9. The Jakarta EE 9 release is source code incompatible with previous releases as the package name has changed from javax.enterprise.* to jakarta.enterprise.*

There were no functional or semantic changes in the specification or APIs.

Jakarta CDI 3.0 Page

See the Jakarta Context Dependency Injection 3.0 for more information on the Jakarta release.

CDI 2.0 (Jakarta)

CDI 2.0 is part of move of Java EE 8 to Jakarta EE 8. The API and specification remain semantically the same, but references to Java EE and associated technologies have been updated to use Jakarta EE and the related updated names.

The source repositories have moved under the Eclipse EE4J organization to the following repositories:

Jakarta CDI 2.0 Page

See the Jakarta Context Dependency Injection 2.0 for more information on the Jakarta release.

CDI 2.0

CDI 2.0 is part of Java EE 8 but is also the first CDI version that support standalone mode on Java SE.

In this version major enhancements are:

What is CDI?

Contexts and Dependency Injection for Java EE (CDI) 1.0 was introduced as part of the Java EE 6 platform, and has quickly become one of the most important and popular components of the platform.

CDI defines a powerful set of complementary services that help improve the structure of application code.

  • A well-defined lifecycle for stateful objects bound to lifecycle contexts, where the set of contexts is extensible

  • A sophisticated, typesafe dependency injection mechanism, including the ability to select dependencies at either development or deployment time, without verbose configuration

  • Support for Java EE modularity and the Java EE component architecture?the modular structure of a Java EE application is taken into account when resolving dependencies between Java EE components

  • Integration with the Unified Expression Language (EL), allowing any contextual object to be used directly within a JSF or JSP page

  • The ability to decorate injected objects

  • The ability to associate interceptors to objects via typesafe interceptor bindings

  • An event notification model

  • A web conversation context in addition to the three standard web contexts defined by the Java Servlets specification

  • An SPI allowing portable extensions to integrate cleanly with the container

Latest Release

The latest release of CDI is 3.0. You can download the spec or browse the javadoc.

CDI 1.0

Contexts and Dependency Injection for Java EE (CDI) 1.0 was introduced as part of the Java EE 6 platform, and has quickly become one of the most important and popular components of the platform.

CDI defines a powerful set of complementary services that help improve the structure of application code.

  • A well-defined lifecycle for stateful objects bound to lifecycle contexts, where the set of contexts is extensible

  • A sophisticated, typesafe dependency injection mechanism, including the ability to select dependencies at either development or deployment time, without verbose configuration

  • Support for Java EE modularity and the Java EE component architecture?the modular structure of a Java EE application is taken into account when resolving dependencies between Java EE components

  • Integration with the Unified Expression Language (EL), allowing any contextual object to be used directly within a JSF or JSP page

  • The ability to decorate injected objects

  • The ability to associate interceptors to objects via typesafe interceptor bindings

  • An event notification model

  • A web conversation context in addition to the three standard web contexts defined by the Java Servlets specification

  • An SPI allowing portable extensions to integrate cleanly with the container

Below is the current list of servers supporting CDI, also listed is the implementation used. Only the last servers major version are listed

Oracle GlassFish 4.1+

using Weld 2.2.x / CDI 1.2

TMAX JEUS 8

using Weld 2.0 / CDI 1.1

WildFly 8.2.0

using Weld 2.2.6 / CDI 1.2

Hitachi Cosminexus v 1.0

using Weld 2.0 / CDI 1.1

JBoss EAP 6.3

using Weld 1.1.23 / CDI 1.0

IBM WebSphere 8.5.x & Liberty profile

using OpenWebBeans 1.2.x / CDI 1.0

Fujitsu Interstage v10.1 / Windows Azure

using Weld 1.1.x / CDI 1.0

Oracle WebLogic 12

using Weld 1.1.3 / CDI 1.0

Apache Geronimo 3.0.1

using OpenWebBeans 1.1.1 / CDI 1.0

JBoss AS 7.1.1

using Weld 1.1.5 / CDI 1.0

Caucho Resin 4.0.17

using CanDI 1.0 / CDI 1.0

Apache TomEE 1.6

using OpenWebBeans 1.2.6 / CDI 1.0

SAP NetWeaver Cloud

using OpenWebBeans 1.x / CDI 1.0

JOnAS 5.3.0

using Weld 1.1.10 / CDI 1.0