users@jersey.java.net

Re: [Jersey] Configuring the singleton strategy when using Grizzly

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 10 Aug 2009 16:04:50 +0200

On Aug 10, 2009, at 3:54 PM, Paul Sandoz wrote:

>
> On Aug 10, 2009, at 2:42 PM, Romain Rouvoy wrote:
>
>> Hi guys,
>>
>> I'd like to know how to configure Jersey to make resource instances
>> to singleton by default.
>> In particular, what need to be added to this piece of code to
>> instantiate resources only once without using the @Singleton
>> annotation:
>
> First you create a class as follows:
>
> package foo;
>
> public class MyResourceConfig extends PackagesResourceConfig {
> public class MyResourceConfig() {
> super("com.sun.jersey.samples.helloworld.resources");
>
> getProperties().put(
>
> ResourceConfig
> .PROPERTY_DEFAULT_RESOURCE_COMPONENT_PROVIDER_FACTORY_CLASS,
> com.sun.jersey.server.impl.resource.SingletonFactory);

The above should be:

      getProperties().put(
         
ResourceConfig
.PROPERTY_DEFAULT_RESOURCE_COMPONENT_PROVIDER_FACTORY_CLASS,
        com.sun.jersey.server.impl.resource.SingletonFactory.class);

Paul.