2009/11/25 John Ament <[email protected]>

> Its always sounded more like a scoping thing to me, and you kind of
> sum it up as well.  With @Resource, you're generally talking about
> something that's been configured on the app server and sits somewhere
> in the JNDI tree (typically in the app server global).  @Inject though
> is always local to the application itself.  I can't recall any
> examples with two standalone EAR files sharing resources via @Inject
> (nor does it sound like a good idea).


Strictly speaking @Inject just decorates members that can be injected.
It doesn't specify where the injected instances come from, or how they
are configured - which is why I said @Resource has extra semantics.

There's no reason why you couldn't have a system that injected shared
resources according to @Inject annotations (ie. using them as a marker)
along with a @Named annotation to name the JNDI resource.

And as I mentioned earlier, you could have @Resource and @Inject on
the same class member - probably overkill, but it would mean that the
component could be used in both JEE and JSE applications. *

So, basically @Resource says more about the injection than @Inject
(which is more general) - which one you choose depends on what you
expect to inject and what semantics you want to apply.

[ * this doesn't necessarily introduce any extra runtime dependencies,
  if you don't have the JSR-250 jar on your classpath you won't see the
  @Resource annotations, and vice versa for JSR-330 ]

 In our setup, we have a couple
> of services deployed as standalone JAR files (reusable logic that many
> of our apps all use), these can be injected via @EJB so I anticipate
> them being able to be injected via @Inject if we move to CDI.
>
> On Nov 25, 5:32 am, AlexisMP <[email protected]> wrote:
> > I think it's fair to say that in a JavaEE 6 environment @Inject really
> > only makes sense in the context of CDI (jsr299).
> >
> > Without CDI @Resource remains a (loosely typed) solution which Now
> > also applies to the new javax.annotations.ManagedBean.
> >
> > In GlassFish v3, @Resource is also used to inject OSGi declarative
> > services in regular JavaEE artiacts.
> >
> > --Alexis
> >
> > On 25 nov. 2009, at 10:38, Fabrizio Giudici <
> [email protected]
> >
> >  > wrote:
> > > Stuart McCulloch wrote:
> >
> > >> Or you could always support both annotations, as they're not mutually
> > >> exclusive.
> >
> > > Great. You also answered to a couple of questions that I hadn't put
> > > yet ;-)
> >
> > > --
> > > 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 athttp://
> groups.google.com/group/javaposse?hl=en
> > > .
>
> --
>
> 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.


Reply via email to