users@jersey.java.net

Re: [Jersey] Newbie question: How do I inject objects into resources

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 24 Mar 2009 12:30:39 +0100

On Mar 24, 2009, at 12:11 PM, amsmota_at_gmail.com wrote:

> It will work in Spring IoC, then?
>

Yes. Essentially for a Spring managed resource or provider class
Jersey will defer totally to Spring to get an instance of that class.

Jersey will inject it's stuff correctly onto Spring beans (proxied or
otherwise) for the singleton and prototype scopes (it should also work
OK for other Spring scopes as well).

Paul.

> Cheers.
>
> On Mar 24, 2009 10:36am, Paul Sandoz <Paul.Sandoz_at_sun.com> wrote:
> >
> > On Mar 24, 2009, at 11:17 AM, António Mota wrote:
> >
> > I'm wondering here, are those injectable thingies part of JAX-RS
> or Jersey? Or putting in another words, those injectable thingies
> will work with any container that supoports jax-rs or only in Jersey
> +Glassfish?
> >
> >
> >
> > The injectable thingies are Jersey specific. They are not
> Glassfish specific and will work with other HTTP-based containers.
> >
> >
> > JSR 299 will allow portable injection of stuff for EE 6
> applications.
> >
> >
> > Paul.
> >
> >
> > Cheers._______________________________________________
> >
> > Melhores cumprimentos / Beir beannacht / Best regards
> >
> > António Manuel dos Santos Mota
> > _______________________________________________
> >
> >
> >
> > 2009/3/24 Paul Sandoz Paul.Sandoz_at_sun.com>
> > Hi Mats,
> >
> > On Mar 24, 2009, at 9:34 AM, Mats Henricson wrote:
> >
> > From: Craig.McClanahan_at_Sun.COM [Craig.McClanahan_at_Sun.COM]
> > Why is this so much more complicated with Jersey?
> > Because Jersey does not pretend to play in the IoC framework
> space. It would much rather integrate with IoC
> > frameworks, so you don't have to choose one approach for your REST
> resource classes and some other
> > approach for your back end services.
> >
> > This explanation would make more sense if your example (of how to
> get a
> > Database Connection object inserted) was not an example of how
> Jersey
> > "integrates with IoC frameworks" but instead an example for how to
> manually
> > do the integration.
> >
> > Which is something completely different, of course.
> >
> > Me myself is struggling with writing JUnit tests of Jersey
> components over
> > HTTP, but I can't find a single example out there. There are lots
> of examples
> > for how to autowire Jersey code into execution environments like
> GlassFish,
> > but none for JUnit. Am I the only TDD enthusiast using Jersey?
> >
> >
> >
> > The Jersey samples make extensive use of unit tests with embedded
> containers. You can get all the samples here:
> >
> > http://download.java.net/maven/2/com/sun/jersey/samples/jersey-samples/1.0.2/jersey-samples-1.0.2-project.zip
> >
> > (or individually).
> >
> > We are working on making this easier with a jersey test framework
> (that Imran mentions) so one can extend from an abstract test case.
> This should be going into the trunk very soon. Any reviews/feedback
> on this would be very much appreciated.
> >
> >
> > It seems like I have to write my own subclass of
> PackagesResourceConfig,
> > since my Resource class needs injection of other objects. Right?
> >
> >
> >
> > What objects do you want to inject?
> >
> > PackagesResourceConfig is the configuration strategy for scanning
> for resource and provider classes. You can of course extend this if
> you want to add your own classes and singleton instances
> explicitly. You can use the @Provider mechanism to register your
> own injectables if you wish and those providers would get picked up
> the scanning if using PackagesResourceConfig.
> >
> > Hope this helps,
> > Paul.
> >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> > For additional commands, e-mail: users-help_at_jersey.dev.java.net
> >
> >
> >
> >
> >
> >
> >
> >
> >