JSR-299: Contexts and Dependency Injection for Java EE


Pete Muir, contributor


We asked Pete Muir about how Red Hat is a leading force for open standards, and about the role the JBoss Community and JBoss Enterprise Middleware play in promoting them.

Q: Please tell a little bit about yourself, your job title, and what projects you are currently involved in?

A: My name is Pete Muir, and I am the project lead for Seam, an application framework for enterprise Java, and Weld, the reference implementation of JSR-299. I represent JBoss on the JSF expert group. I'm also leading the development of the JSR-299 TCK.

I am currently employed by JBoss, a division of Red Hat, as a core developer working on JBoss open source projects. Before working for Red Hat, I used and contributed to Seam whilst working for a UK based staffing agency as IT Development Manager.

Q: What is the JSR-299?

A: JSR-299 is an elegant set of services for Java EE components that draws upon ideas from JBoss Seam and Google Guice. While many of the features provided by JSR-299 (dependency injection, contextual lifecycle, configuration, interception, event notification) are familiar, the innovative use of meta-annotations is uniquely expressive and typesafe.

JSR-299 defines a unifying dependency injection and contextual lifecycle model for Java EE 6:

• a completely new, richer dependency management model
• designed for use with stateful objects
• integrates the "web" and "transactional" tiers
• makes it much easier to build applications using JSF and EJB together
• includes a complete SPI allowing third-party frameworks to integrate cleanly in the EE 6 environment

Q: How does this standard benefit users? What problems will it solve?

A: The use of these services significantly simplifies the task of creating Java EE applications by integrating the Java EE web tier with Java EE enterprise services. In particular, EJB components may be used as JSF managed beans, thus integrating the programming models of EJB and JSF.

The key theme of JSR-299 is loose coupling, which allows for technical and business concerns to be compartmentalized. This is realized through Dependency Injection, a type safe event model which implements the observer/observable pattern, interceptors (which separate technical concerns from business concerns) and decorators which compartmentalize business concerns.

We are concentrating on four groups of use cases. Firstly, web frameworks - it should be really easy to integrate JSR-299 with another web framework (such as Wicket). Then Business Process Management engines such as jBPM or Oracle's BPM - this motivates the use of a hierarchy management model. The third is that people using existing dependency injection frameworks be they Spring, Seam, Guice or some other DI mechanism need to be able to integrate their existing code with CDI, and the fourth is RESTful web services via JAX-RS.

Q: How will JBoss build on this standard?

A: JBoss will provide tooling around CDI (the reference implementation of JSR-299) as part of the JBoss Tools open source project (which forms the core of JBoss Developer Studio) to further improve developers productivity. JBoss will also a number value-add extensions to the specification, including integration with the Seam 2 and Spring programming models, the Apache Wicket web framework, and JBoss jBPM. JBoss will also provide the ability to run CDI in plain servlet environments such as Tomcat, and Java SE.

Seam 3 will be built on the JSR-299 core, and provide additional modules (which are portable to any 299 implementation) supporting enterprise functionality such as sending email, reporting to PDF or spreadsheet, unified security across all tiers of your application and JBoss RESTeasy integration.

Q: Where can I learn more about JSR-299?

A: Here are a few links to get you started:

http://in.relation.to/Bloggers/Tag/Web+Beans
http://seamframework.org/WebBeans
http://jcp.org/en/jsr/detail?id=299