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);
}
}
Then modify lines 8 and 9 to be:
8 initParams.put("javax.ws.rs.Application",
9 "foo. MyResourceConfig");
>
> PS. I already tried this without success:
>> initParam
>> .put
>> ("com
>> .sun
>> .jersey
>> .config.property.DefaultResourceComponentProviderFactoryClass",
>> "com.sun.jersey.server.impl.resource.SingletonFactory");
>
It is a bug, could you log an issue?
Currently it only works when a Java class is used and not when the
fully qualified name of a Java class is used.
Paul.