users@jersey.java.net

Re: [Jersey] Filter Spring beans by package before registering as resource

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Thu, 29 Jul 2010 16:40:20 +0200

Hi John,

You can specify a child application context to use for each
SpringServlet thereby scoping the spring beans per servlet:

https://jersey.dev.java.net/nonav/apidocs/latest/contribs/jersey-spring/com/sun/jersey/spi/spring/container/servlet/SpringServlet.html
#CONTEXT_CONFIG_LOCATION

Paul.

On Jul 26, 2010, at 11:46 PM, John B Staley wrote:

> Hi Frédéric,
>
> I don't really see what is different in your example so no, it does
> not work; the reason is SpringServlet automagically registers all
> Spring beans as resources, the "packages" filter has no effect for the
> Spring beans. At least not as far as I have been able to tell.
>
> Regards,
> John
>
>
> 2010/7/26 Frédéric Bouquet <bouquet.frederic_at_gmail.com>:
>>> Hi,
>>>
>>> I'm using Jersey and basically what I want to accomplish is having
>>> multiple servlet mappings deployed within the same Spring context
>>> with
>>> each containing a different set of Spring beans.
>>>
>>> Currently each SpringServlet will register every Spring annotated
>>> root
>>> resource. I would like to have a way of specifying what package
>>> should
>>> belong to each servlet, i.e. like this (but it scan the Spring beans
>>> instead of scanning the classpath)
>>>
>>> <servlet>
>>> <servlet-name>jersey-one</servlet-name>
>>> <servlet-
>>> class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</
>>> servlet-class>
>>> <init-param>
>>> <param-name>com.sun.ws.rest.config.property.packages</param-
>>> name>
>>> <param-value>my.package.for.jersey.one</param-value>
>>> </init-param>
>>> </servlet>
>>> <servlet>
>>> <servlet-name>jersey-two</servlet-name>
>>> <servlet-
>>> class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</
>>> servlet-class>
>>> <init-param>
>>> <param-name>com.sun.ws.rest.config.property.packages</param-
>>> name>
>>> <param-value>my.package.for.jersey.two</param-value>
>>> </init-param>
>>> </servlet>
>>>
>>> Any hints on how I can accomplish this?
>>>
>>> Thanks in advance,
>>>
>>> Regards,
>>> John
>>
>> Hi,
>>
>> I don't know spring but maybe something like this to declare the
>> "set"
>> of resources to share :
>>
>> <servlet>
>> <servlet-name>jersey-set</servlet-name>
>> <servlet-
>> class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</
>> servlet-class>
>> <init-param>
>> <param-name>com.sun.ws.rest.config.property.packages</param-
>> name>
>> <param-value>my.package.for.jersey</param-value>
>> </init-param>
>> </servlet>
>>
>> and then to map the servlets to resources :
>>
>> <servlet-mapping>
>> <servlet-name>jersey-set</servlet-name>
>> <url-pattern>/*</url-pattern>
>> </servlet-mapping>
>>
>>
>> Does it work ?
>>
>>
>> --
>> Frédéric Bouquet
>> http://www.espacedefouille.org/
>>
>> ---------------------------------------------------------------------
>> 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
>