What Is The Relation Between JSR-299 and JSR-330 In Java EE 6? Do We Need Two DI APIs?
There was/is a lot of confusion, as JSR-330 (Dependency Injection for Java) led by Rod Johnson (SpringSource) and Bob Lee (Google Inc.) became a part of Java EE 6. JSR-330 is very simplistic. It comes with own few annotations from the package: javax.inject. The package contains the following elements: Inject, Qualifier, Scope, Singleton, Named and Provider. Its the definition of the basic dependency injection semantics.
JSR-299 (Java Contexts and Dependency Injection), with Gavin King as lead, uses JSR-330 as base and enhances it significantly with modularization, cross cutting aspects (decorators, interceptors), custom scopes, or type safe injection capabilities. JSR-299 is layered on top of JSR-330.
It is amusing to see that the built-in qualifier @Named is not recommended and should be used only for integration with legacy code:
"The use of @Named as an injection point qualifier is not
recommended, except in the case of integration with legacy code that
uses string-based names to identify beans."
[3.11 The qualifier @Named at injection points, JSR-299 Spec, Page 32]
The relation between JSR-299 and JSR-330 is comparable to the relation between JPA and JDBC. JPA uses internally JDBC, but you can still use JDBC without JPA. In Java EE 6 you can just use JSR-330 for basic stuff, and enhance it on demand with JSR-299. There is almost no overlap in the practice. You can even mix JSR-299 / JSR-330 with EJB 3.1 - to streamline your application.
- Login or register to post comments
- 7668 reads
- Printer-friendly version
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)




Comments
Nicolas Frankel replied on Thu, 2010/01/07 - 6:13am
Cej Hah replied on Thu, 2010/01/07 - 9:10am
"It is amusing to see that the built-in qualifier @Named is not recommended and should be used only for integration with legacy code"
I don't think you're comprehening this very well or your wording isn't making sense. The spec says "The use of @Named as an injection point qualifier is not recommended". However, you very much need @Named to declare the bean EL name. There is nothing amusing about that.
adam bien replied on Thu, 2010/01/07 - 12:14pm
in response to: BillyBob321
Solomon Duskis replied on Thu, 2010/01/07 - 2:12pm
Henk De Boer replied on Thu, 2010/01/07 - 3:13pm
in response to: sduskis
That's IT dude... newer = better.
Spring was once the king of DI, but now we have something better.
But let's not cry. This happens all the time. Matrox was once the king of main stream video cards, but new comer to video nvidia understood the "needs of the video environment much better..."
Solomon Duskis replied on Thu, 2010/01/07 - 3:25pm
in response to: henk
Both the Spring and Guice camps have expressed strong reservations about the details of CDI. Bob Lee was on JSR 299 and left due to incompatible technical vision. I have yet to see convincing evidence that CDI is indeed better than the commonly used alternatives.
Just because there has been innovation in other fields, doesn't mean that CDI is THE way to go for DI. I'd love to see a fair comparison between CDI's approach and the alternatives that would show me the pitfalls for complex enterprise software. I'd rather stick with the tried and true de facto standard, for now, before plunging into a so called "standard" that recreates complex, mostly unproven functionality from scratch.
Reza Rahman replied on Thu, 2010/01/07 - 8:24pm
in response to: sduskis
Solomon,
What's a fair comparison is obviously in the eye of the beholder, but we just discussed some of this here: http://www.theserverside.com/news/thread.tss?thread_id=58858. Maybe it is of some help?
As I see it, Rod and Bob Lee went their own route because of political, not technical concerns. For one, I have yet to find a purely technical critique of CDI from those camps...
Hope it helps,
Reza
Gavin King replied on Thu, 2010/01/07 - 6:53pm
in response to: sduskis
Precisely where have the Spring folks expressed and explained these "strong reservations about the details"? Isn't it interesting that they havn't actually let the rest of us know what their detailed reservations are? And if they had such detailed reservations, why didn't they join the 299 EG when invited, or at least send technical feedback to the EG, or explain their reservations in their JCP non-votes? Where can we all go to discover what these "detailed issues" were? In fact, if they had such detailed reservations, why did Spring not vote on the CDI (or EE6) JSRs?
As it happens, we do know what Bob Lee's "detailed issues" were:
1. That CDI uses proxies for normal-scoped beans.
2. That CDI scans bean deployment archives to automatically discover beans that can be injected.
Now, interestingly, recent versions of Spring have adopted both these ideas. So Bob's "detailed issues" are also, presumably, reasons to not use Spring? Of course, in the opinion of others, both these items are useful features of CDI, that make CDI easier to use than Guice. Oh, and if these issues are such problems, why did Google vote yes on the CDI JSR?
Oh, and by the way:
1. I'm pretty sure that Seam has a bigger user base than Guice, making it one of the market leaders in dependency injection. So discounting my view as a "newcomer" is perhaps unfair, don't you think?
2. Both Bob Lee and myself have publically expressed very strong reservations about Spring. And both myself and, I'm certain, the Spring folks, have reservations about Guice. Does that mean that you shouldn't use Spring? Or Guice? Or does it mean that you should actually pay attention to more disinterested observers than to authors of competing software, or try things out for yourself?
Reza Rahman replied on Thu, 2010/01/07 - 8:33pm
in response to: gk74926
The problem, of course is finding such a disinterested observer...sometimes I feel like Java needs the equivalent of "consumer reports" that all the "product manufacturers" then can be unhappy with :-).
Cheers,
Reza
George Jiang replied on Thu, 2010/01/07 - 11:50pm
in response to: gk74926
George Jiang replied on Fri, 2010/01/08 - 12:19am
in response to: george.jiang
Gavin King replied on Fri, 2010/01/08 - 2:49am
See here:
http://seamframework.org/Weld/JSR299AndWeldOverview#H-HowDoesSeamRelateToWeldJSR299Andy Jefferson replied on Fri, 2010/01/08 - 4:23am
in response to: Reza Rahman
The JCP has a long history of such a policy, doing things for political reasons rather than technical. Nothing new there ...
Martijn Verburg replied on Fri, 2010/01/08 - 4:48am
in response to: Reza Rahman
Fab Mars replied on Fri, 2010/01/08 - 8:36am
Politics....politics and money.
Spring didn't vote because they wouldn't want to take part to the standardization of a much greater and more to-the-point framework than theirs, and which is likely to take away some of their business.
Much of these "strong reservations" is irrelevant. There's no point in even commenting that.
330 is here for poliltical reasons too. But that's not yesterday's news.
http://in.relation.to/Bloggers/CommentsOnAnnotationsForDependencyInjection
Would you fly in a refurbished Tupolev bomber, or a recent Airbus skyliner?
I don't know about you. I'll go for CDI airlines.
Gavin King replied on Fri, 2010/01/08 - 8:35am
This is exactly the right approach. Try things out for yourself. Pick the solution that works best for you. I am very, very confident that a very large % of the people who actually try out Java EE 6 and CDI will eventually decide to go down that path.
Reza Rahman replied on Fri, 2010/01/08 - 1:07pm
in response to: karianna
To be honest, I am only half-joking about the "consumer reports" for Java part. I personally think it's very doable and could even be worthwhile monetarily. I think the biggest challenge is for it to come from a credible source such as an independent non-profit that people would trust as competent and neutral. Honestly, I wish I had the time to see if I can help get it off the ground...oh well... maybe some other folks?
Cheers,
Reza
Henk De Boer replied on Fri, 2010/01/08 - 3:52pm
A while back you wrote the first part of a series of articles about JSR-299/CDI: Dependency Injection in Java EE 6
This article was really well written. Are there still more parts coming? I hope so :)
Reza Rahman replied on Fri, 2010/01/08 - 4:35pm
in response to: henk
Henk,
Yep, the next part should be out in a week or so. Things have been tough on my schedule year-end with the Resin work spinning up and the holidays, etc. I am thinking the series should wrap up in a few months (perhaps in four/five parts).
BTW, thanks for the kind words.
Cheers,
Reza
Liam Knox replied on Fri, 2010/01/08 - 7:37pm
JSR 299 however , I cannot see much straight forward documentation about it. For example This Reads like a binary file.
Personally I dont care of EJB or JSF, why should I ? I just want to relate one bean to another and inject propertys. Maybe JSR 299 is harking back to the good old days of EJB 2 and just inventing and perscribing ideas that in practice people have little need for.
Cloves Almeida replied on Sat, 2010/01/09 - 2:02pm
I've spent a good portion of the last two years developing in Seam. It's a great plataform, really. Makes using the JEE+JPA+JSF seamless and the concept of Conversations, once you get it, it's really useful. However, as a good "customer" I'd like to pinpoint a few areas where it could be improved:
- JSF 1.x sucks big time. The large majority of my hard to resolve bugs are related to JSF and it's inflexible approach. JSF 2.0 seems to be better and the Richfaces guys have done miracles, but still, why invent a component model when we can simply use HTML+JavaScript and something lightweight like Wicket for binding. Wicket and REST+Json should really be the focus instead of JSF.
- Application level modularity should be improved. Would be very useful to package an application into smaller components with runtime versioning and dependency checking. If not only to improve redeployment speeds. Which gives us next:
- Development cycle (deploy-test-redeploy) should be improved. As the application grows, its very unproductive to wait sometimes over a minute to wait for the entire app to redeploy when you're testing a smallish improvement. To the point it makes EAR deployment unfeasible when compared with WAR+hot deploy+Jetty. But not using an AS beats the whole point of "enterprise development plataform" right?
Then again, I thanks a lot GK and JBoss team for the effort - developing with Seam makes me as productive as if I was using Django (I can even use groovy for functional stuff).George Jiang replied on Mon, 2010/01/11 - 5:21pm
in response to: gk74926