Contexts and Dependency Injection for Java Specification | Contexts and Dependency Injection
Contexts & Dependency Injection for Java
Highlights
CDI 3.0
CDI 2.0(Jakarta)
CDI 2.0
CDI 1.1 & 1.2
CDI 1.0
Spec pages
CDI 3.0 - Jakarta EE 9
CDI 2.0 - Jakarta EE 8
CDI 2.0 - JSR 365
CDI 1.2 - JSR 346
CDI 1.0 - JSR 299
Servers
Overview
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 (
) and alternatives (
) 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 (
Add
EventMetadata
) to allow inspection of event metadata
Add
@Vetoed
annotation allowing easy programmatic disablement of classes (
Many improvements for passivation capable beans, including
@TransientReference
allowing instances to be retained only for use within the invoked method or constructor (
and
Add scope activation and destruction callback events (
Add
AlterableContext
allowing bean instances to be explicitly destroyed (
Add automatic enablement of CDI for beans with a scope annotation, and EJBs, in Java EE (
Add class exclusion filters to
beans.xml
to prevent scanning of classes and packages (
Add
Unmanaged
allowing easy access to non-contexutal instances of beans (
Add
CDI
allowing easy accesss to the current CDI container (
Add
AfterTypeDiscovery
event, allowing extensions to register additional types after type discovery (
Add
@WithAnnotations
as a way of improving extension loading performance (
Many minor improvements to portable extensions (
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:
CDI Api and Spec
CDI TCK
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:
The spec was split into
3 parts
to add the support for Java SE.
API to
boot CDI in Java SE
Observers (i.e. events)
ordering
Asynchronous event
Configurators
for major SPI elements
Possibility to
configure or veto observer methods
Add
built-in annotation literals
Make possible to
apply interceptor on producers
Alignment on Java 8 features (streams, lambdas, repeating qualifiers)
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
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
Tweets by @cdispec
US