2009/11/25 Fabrizio Giudici <[email protected]> > Hi. > > Can somebody please quickly recap the difference between @Resource and > @Inject from JSR330? Afaik JSR330 has been definitely approved. My need > is to use an annotation to perform dependency injection that is the most > widely accepted - I'm using @Resource for a tiny, specifically focused > resource injection library and would like to have the resulting > annotated code to be as much as compatible with other injection > frameworks as possible (at wide range: JSE, JEE etc...). AFAIK @Inject > will be used as a standard, but I'd like to have this confirmed. THanks. >
[ caveat: I help out with Guice, so the following opinion might be biased... ] IMHO @Resource has extra semantics over and above simple injection, from javadoc: "The Resource annotation marks a resource that is needed by the application." @Resource is implicitly tied with JNDI resources, and what's more the exact meaning behind it can change depending on whether it annotates a method/field member, or a class. If your library is definitely targeting JNDI injection rather than general injection then probably @Resource is the one to choose. On the other hand @Inject simply marks out members of a class that can be injected: "Identifies injectable constructors, methods, and fields." which makes it better for general injection - see also Bob's comment at the end of: http://code.google.com/p/atinject/issues/detail?id=15#c15 BTW, the javax.inject API is already available on central along with src and javadoc: http://repo1.maven.org/maven2/javax/inject/javax.inject/1/javax.inject-1.jar However, if you want something that's definitely supported by legacy/existing systems then @Resource might have more coverage - although I expect that to change over the next few years as people and frameworks starting picking up @Inject... Or you could always support both annotations, as they're not mutually exclusive. -- > Fabrizio Giudici - Java Architect, Project Manager > Tidalwave s.a.s. - "We make Java work. Everywhere." > weblogs.java.net/blog/fabriziogiudici - www.tidalwave.it/people > [email protected] > > -- > > You received this message because you are subscribed to the Google Groups > "The Java Posse" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<javaposse%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/javaposse?hl=en. > > > -- Cheers, Stuart -- You received this message because you are subscribed to the Google Groups "The Java Posse" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/javaposse?hl=en.
