users@jersey.java.net

Re: [Jersey] Dependency resolution for container request and response filters

From: Brian Gilstrap <brian_at_ociweb.com>
Date: Thu, 14 Jan 2010 08:56:39 -0600

On Jan 14, 2010, at 6:27 AM, Paul Sandoz wrote:

> Hi Brian,
>
> Since you are using Spring you could register those filter classes as singleton spring beans and Jersey will defer to Spring to obtain references to those classes. Then you can use Spring-based injection, including constructor or field-based injection as supported by Spring. Will that work for you?
>
> Otherwise there is a Jersey specific way i can send more details on if the Spring approach is not suitable.

You have hit upon a related issue. I would like to understand how to use Jersey with Spring and with other IOC approaches. I need to go back and make a copy of my code which does not use Spring and figure out how to make everything work. In particular, I want to know what other IOC approaches work with Jersey, both in terms of things like my filters and in terms of resource objects that are instantiated by Jersey but which need to have additional objects injected for use.

So, that leads me to two things:

1) Is there an example of a singleton spring bean in the sample code I can learn from? (I tried doing this once in the past and had some trouble, so I punted and took a different route at the time)

2) Can you please tell me the Jersey-specific way to do the dependency injection?

Thanks!
Brian