I've just started using Jersey
to implement a JAX-RS
resource. One thing I haven't been able to figure out is how I give it access to some dependency in my Java application.
This is not a duplicate of How to inject an object into jersey request context? or Dependency injection with Jersey 2.0, at least as far as I can tell.
E.g. I would like to give the following resource access to an instance of MyObject
, which is created somewhere else in the program.
@Path("myResource")
public class MyResource
{
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response foo()
{
// I want to call get() on an instance of MyObject
// how do I get this instance of MyObject into the resource?
myObject.get();
return Response.status(Response.Status.OK).entity("response").build();
}
}
This seems like such an obvious question but I can't find an answer.