Java EE 6: Context and Dependency injection

As in its previous release, Sun seems to focus on including de facto standards in the Java EE new release. In Java EE 1.5, one of the major improvements was to add a persistence API (aka JPA - part of JSR-220), based on Hibernate and other ORM api.

javaAs in its previous release, Sun seems to focus on including de facto standards in the Java EE new release. In Java EE 1.5, one of the major improvements was to add a persistence API (aka JPA - part of JSR-220), based on Hibernate and other ORM api.

In Java EE 6, Sun has included an implementation of the JSR-330 to provide the best-of-breed dependency injection features from standard libraries such as Jboss seam, Spring or Juice, and to extend those by adding some innovations.

In JavaEE 5, dependency injection was only possible within the Enterprise container, restricted to resources such as JMS connection factories, datasources, JPA entity managers and factories and EJB. JavaEE 6 extends this to any bean, still in an annotation-driven programming. This new feature is based on the existing JSR-330 (Dependency injection for Java), adding new annotations such as @Injection, @Qualifier or @ScopeType.

The Context and Dependency Injection allows defining the bean's scope. Several scopes are available, such as Dependent, ApplicationScoped, RequestScoped, SessionScoped and, Seams users would recognize this one, ConversationScoped.

As we can see, enhanced IOC and context management becomes part of JavaEE core, and I think all Spring or other IOC framework users would agree this new Java EE feature is going in the way of facilitating JavaEE programming.

Resources:

Java EE 6 specification: http://java.sun.com/javaee/technologies/index.jsp
JSR-220: Enterprise JavaBeans 3.0, http://jcp.org/en/jsr/detail?id=220
JSR-330: Dependency injection for Java, http://jcp.org/en/jsr/detail?id=330
TheserverSide.com article, http://www.theserverside.com/tt/articles/article.tss?l=DependencyInjectioninJavaEE6

Digital news!

Are you as digitally addicted as we are? We can supply you with a regular dose of digital news. Simply sign-up, or click to Follow us online.

About the author

Jacques Desmazières
Jacques Desmazières

J2EE/Java senior consultant. Expert in Software architecture and technical design, and involved in the b-i quality commitee. Before working for blue-infinity he was the technical director of a banking software editor on the French Riviera and also spend some years as a system integration consultant.