users@jersey.java.net

Re: [Jersey] ResourceContext questions

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 08 Dec 2009 15:45:21 +0100

On Dec 8, 2009, at 3:41 PM, FSauer_at_dsthealthsolutions.com wrote:
>
>
> 1) is there a way to make ResourceContext always create a new
> instance (as opposed to look up an existing one in a map). I am
> trying to create a collection of these things and the caching trips
> me up
>
> Do you want to utilize a life-cycle of "per-instance" ?
>
> Yes, that would do it! Do we have that already and I missed it?
>
>

Jersey does not currently have support for that.


>
> 2) Does ResourceContext also make use of @Component and @Resource
> annotations?
>
> Yes. ResourceContext will defer to what ever IoC frameworks are
> registered.
>
>
> Does Spring support a per-instance life-cycle? If so it may just
> work, but i have not tested it and may require some minor tweaks to
> the Spring integration.
>
> Yes, that's what "prototype" does...
>

OK. Then it should work if the instances are instantiated *and*
managed by Spring.



> However, you cannot create instances of the same resource class for
> different life-cycles.
>
> That's acceptable (and understandable)
>
>
>
> I need to inject a spring managed service bean into the created
> resources. Is there a SpringAwareResourceContext?
>
> Can I create my own ResourceContext implementation? Using @Provider
> perhaps?
>
>
> You could override the one provided by defining your own injectable
> provide. But i am not sure it is necessary.
>
>
> Agreed, if I have a per-instance scope and spring injection works,
> then I don't need to do this
>

Correct.

Paul.