users@jersey.java.net

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

From: António Mota <amsmota_at_gmail.com>
Date: Tue, 24 Mar 2009 10:17:21 +0000

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?

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
>
>