users@jersey.java.net

Re: [Jersey] Destroying injected context at the end of resource lifecycle

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 06 Feb 2009 09:37:36 +0100

Hi Alex,

If you are using Jersey 1.0.1 you can annotate a method with
@PreDestroy on a resource class and when the resource goes out of
scope that method will get called.

If you do not want to use @PreDestroy on a resource classes an
alternative is to add ContainerResponseFilter to do the clean up of
any persistent managers that have been injected and utilized. The
injection provider could add the injected persistence manager
instances to a List that is a property on the HttpContext.

In the above I presuming that the injection of PersistenceManager
instances are pre-request. Is that correct? If not then it will be
necessary to override the ServletContainer and the destroy method to
clean up singleton-based instances.

Note that Jersey is not a generic framework for life-cycle and
injection. If you need that then I recommend using Spring (Guice
support will be available in the next release).

Paul.

On Feb 6, 2009, at 12:39 AM, Roytman, Alex wrote:

> Hello,
>
> I am very new to Jersey, so forgive me if my question is silly.
>
> I would like to annotate some resources with a custom annotation to
> inject JDO PersistenceManager but I must have some way to close it
> at the end of resource lifecycle. I was browsing source code but
> could not find any way to accomplish it.
>
> Could you point me in right direction?
>
> Thank you,
> Alex