I've seen a bunch of times several ways a JAXRS resource is configured.
I mean, sometimes I see they are annotated as @Singleton
, @Stateless
, @ApplicationScoped
, @RequestScoped
, and even without any annotation or using both of them.
javax.enterprise.context.RequestScoped
javax.enterprise.context.ApplicationScoped
javax.ejb.Stateless
javax.ejb.Singleton
javax.inject.Singleton
Which annotation should I use?
What has javax.ejb
to do with a JAXRS resource?
By other hand, I'd also like to know about how to work exactly with @Context
annotation.
I mean, I've seen this applied on a parameter, also in a class field.
@Path("entity")
public class EntityResource {
@Context
private Request request;
@POST
public Response create(Entity entity) {
this.request...
}
}
or,
@Path("entity")
public class EntityResource {
@POST
public Response create(Entity entity, @Context Request request) {
request...
}
}
How would i proceed?