Help

I'm the creator of Hibernate, a popular object/relational persistence solution for Java, and Seam, an application framework for enterprise Java. I've also contributed to the Java Community Process standards as Red Hat representative for the EJB and JPA specifications and as spec lead of the CDI specification. At Red Hat, I'm currently working on Ceylon, a new programming language for Java and JavaScript VMs.

I now blog at the Ceylon blog.

I also post stuff on G+.

Location: Barcelona, Spain
Occupation: Fellow at JBoss, a Division of Red Hat
Archive 'Contexts and Dependency Injection'
My Books
Java Persistence with Hibernate
with Christian Bauer
November 2006
Manning Publications
841 pages (English), PDF ebook
Hibernate in Action
with Christian Bauer
August 2004
Manning Publications
408 pages (English), PDF ebook
29. Mar 2011, 11:12 CET, by Gavin King

Andy Gibson and Rick Hightower have announced the CDISource project.

Some people have wondered why CDI requires an explicit @Named annotation before a bean can be accessed using EL? Why not just give all beans names by default?

Well, the reason is that EL has a single flat namespace. There's no notion of qualified names in EL. Experience in the JSF community is that avoiding duplicate names is harder than it looks, especially when the application includes multiple modules maintained by different teams. Remember that not all CDI beans are intended to form part of the user interface layer. A Java EE 6 application might include modules defining an independent business layer, whose beans should always be accessed via typesafe dependency injection instead of non-typesafe EL names. Beans in these modules should not have EL names, in order to avoid polluting the namespace of the UI layer.

Still, the combination @Named @RequestScoped is going to be super-common in JSF applications. So CDI includes a built-in stereotype that encapsulates these defaults. The @Model stereotype refers to the M role in the MVC pattern. We recommend that all JSF user-interface-oriented beans be annotated @Model to both save a little typing (one annotation instead of two), and, more importantly, to make clear their architectural role in the system.

Indeed, even when you have a UI model bean that's not @RequestScoped, I recommend annotating it @ConversationScoped @Model rather than @Named @ConversationScoped. The two options have the same functional effect, but the first combination communicates more information to someone reading your code later, and makes it easy to quickly search for all UI model beans.

(Of course, if, for whatever reason, you don't like @Model, you can always define your own stereotype to fulfil a similar purpose. The CDI container doesn't treat @Model in any special way.)

08. Jan 2010, 02:32 CET, by Gavin King

Since the release of Weld and Java EE 6, there's been a heap of activity in the Weld user forum, and especially a lot of questions about problems related to framework development. You can do some kinds of generic programming in CDI just using managed beans, producer methods and InjectionPoint. But if you want to get serious, you're eventually going to have to embrace the portable extension SPI. Here's a couple of examples of how people are using this SPI.

Steven Verborgh has written a nice tutorial showing how to implement a custom JSF view scope for CDI. Henri Chen has integrated the ZK framework with CDI (hopefully other web frameworks won't be far behind). Matt Corey has been experimenting with environment configuration via JNDI.

Meanwhile, I've been working on compiling user feedback into a list of enhancements to the SPI. We plan to roll the most important items into the first CDI maintenance release.

UPDATE: for completeness, I should also link Pete Royle's Quartz scheduling extension.

18. Dec 2009, 01:35 CET, by Gavin King

Andy Gibson has written a nice tutorial to help you get started with JSF 2 and CDI using Netbeans and Glassfish. It's great to see that both Netbeans and Intellij 9 already have excellent support for Java EE 6.

12. Dec 2009, 00:10 CET, by Gavin King

As I'm sure you've all seen, Java EE 6 has gone final. You can now download the Final Release of the Contexts and Dependency Injection, Bean Validation, Java Persistence API 2 and Java Servlet 3 specifications from jcp.org, and read the linked javadoc for the entire platform. It's also a good chance to check out the Java API for RESTful Web Services specification, which now includes CDI integration, if you havn't already.

Sun have also published a three-part overview of the new platform and the Java EE 6 tutorial and sample applications.

It's just fantastic to finally see the fruits of all that work :-)

Showing 1 to 5 of 38 blog entries tagged 'Contexts and Dependency Injection'