Hi,
Do you want some kind of singleton object to be injected into the
resource classes (the classes that contain the resource methods
annotated with @GET etc) ?
If, this is going to get a lot easier when we release EE 6 with
support for 299 and managed beans. In the mean time you can do the
following:
@Singleton // see [1]
public class MySingletonResource {
...
}
@Path("/blah")
public class MyResourceClass {
@GET
public ... get(@Context ResourceContext rc) { // see [2]
MySingletonResource msr =
rc.getResource(MySingletonResource.class);
}
}
If you want the MyResourceClass to be a singleton you can do:
@Singleton
@Path("/blah")
public class MyResourceClass {
}
You do not have to use EJBs, but that is one option, but i recommend
only using it with EJB 3.1 and Java EE 6 which significantly improves
the ease of use of EJBs.
Otherwise, if this is not what you require a simple example of what
you want to do will help me understand better your needs,
Paul.
[1]
https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey/com/sun/jersey/spi/resource/Singleton.html
[2]
https://jersey.dev.java.net/nonav/apidocs/1.1.2-ea/jersey/com/sun/jersey/api/core/ResourceContext.html
On Oct 5, 2009, at 2:28 PM, cepam wrote:
>
> Hello,
>
> This is a general question about 'using one business object with
> jersey',
> due to the fact i'm a newbie in web development.
>
> I've implemented a jersey application who manage some URIs. I have
> to create
> one specific object used by all jersey 'methods'. What is the better
> strategy to create this object only one time (no create/destroy for
> each
> request).
>
> I'm using a com.sun.jersey.spi.container.servlet.ServletContainer
> for my
> jersey application.
>
> Is there any init method (javax.servlet library) to override ?
> Is it an obligation to use an EJB ?
> Other solutions ?
>
> Thanks very well for your answers.
> E. L
> --
> View this message in context: http://n2.nabble.com/Business-object-for-jersey-tp3768500p3768500.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>