views:

226

answers:

2

Java EE 6 offers (at least) two Dependency Injection mechanisms: DI annoations from Java EE 5 like @EJB, @PersistenceContext, @Resource ... and the new JSR 330. Can I replace the "old" DI annotations with the more general JSR 330 annotations?

Are there any benefits or drawbacks of the one or other approach? Which one would you use and why?

+3  A: 

Go with JSR 330 annotations. They'll work with other DI frameworks that are up to date, like Spring 3.0.

duffymo
+2  A: 

I think JSR330 annotations are the obvious choice. But it's important to realize that JSR-330 only concerns the using of dependencies, not the definitions.

So you'll still be bound to some proprietary format for defining your beans, if this is guice or spring may be up to your preferences. Most of my spring beans are both producing and consuming dependencies, meaning I'm no less independent from spring now that I was before switching to JSR-330.

krosenvold