You do not need Spring or Guice to enter ServletConfig. Jersey makes through its own injection mechanism. See the simple servlet example that comes with the Jersey sample distribution. Here is an example of code that injects HttpServletRequest and ServletConfig to a resource:
@Path("/resource1") public class ResourceBean1 { @Context HttpServletRequest servletRequest; @Context ServletConfig servletConfig; @GET @Produces("text/plain") public String describe() { return "Hello World from resource 1 in servlet: '" + servletConfig.getServletName() + "', path: '" + servletRequest.getServletPath() + "'"; } }
When deploying a JAX-RS application using the ServCertFig, ServletContext, HttpServletRequest and HttpServletResponse servlets are available for injection using @Context.
Arul dhesiaseelan
source share