users@jersey.java.net

Re: [Jersey] ServletContainer: Specify packages *and* application?

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Tue, 10 Nov 2009 11:09:56 +0100

Hi,

I verified that it works. See attached for a simple maven project.

Note that what can be injected at the construction of an Application
instance is limited. Because the application can itself define further
stuff to be injected or provider components the infrastructure for
most providers will be initialized after the instantiation of the
Application instance.

Paul.







On Nov 10, 2009, at 10:30 AM, Paul Sandoz wrote:

> Hi,
>
> You can add the fully qualified name of the InjectableProvider class
> to the following file:
>
> META-INF/services/jersey-server-components
>
> located in WEB-INF/classes or in an appropriate jar file included in
> WEB-INF/lib. Alternatively you can add the class to the following
> file:
>
> META-INF/services/com.sun.jersey.spi.inject.InjectableProvider
>
> But i recommend using the former.
>
> I have not tried this particular configuration set up. An injectable
> provider injecting stuff into an Application sub-class but i think
> it should work with the latest 1.1.4-ea or 1.1.5-ea SNAPSHOT. Please
> let me know ASAP if it does not.
>
> Paul.
>
> On Nov 10, 2009, at 10:11 AM, Chris Hubick wrote:
>
>> Hi,
>>
>> I have a package containing a generic JAX-RS Application subclass
>> MyApplication, which I am trying to not tie specifically to the
>> Jersey
>> JAX-RS implementation. MyApplication does a lot of heavy lifting to
>> create and provide several singletons (root resources) which are
>> tied to
>> it.
>>
>> I also have a reusable utility package with a custom object MyObject.
>>
>> MyApplication's constructor requires a MyObject.
>>
>> So, I create a separate Jersey-specific utility package with an
>> InjectableProvider implementation for MyObject. Like MyObject, this
>> package is also reusable, and not tied to the MyApplication package.
>>
>> Now, the problem comes when trying to instantiate all this inside
>> ServletContainer. What I would want to do is specify a 'packages'
>> init-param pointing to my InjectableProvider *and* specify an
>> 'application' init-param for MyApplication. Sadly, it does not
>> appear I
>> can do both?
>>
>> It looks as though I can specify a 'resourceConfigClass', but does
>> ResourceConfig allow one to provide an Application whose singletons
>> will
>> be retrieved?
>>
>> In reality, I have many MyObject's, MyApplication's, and
>> InjectableProvider's, which would be combined in various ways as
>> needed
>> depending on the environment. If ResourceConfig is the only
>> answer, is
>> there a way to create and configure one at runtime, so that I don't
>> need
>> to create a separate package for every component combination
>> ResourceConfig implementation? I guess I could write such a thing
>> if it
>> doesn't exist.
>>
>> Thanks for any advice!
>>
>> --
>> Chris Hubick
>> mailto:chris_at_hubick.com
>> http://www.hubick.com/chris/
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>