Get ServletContext in Application

前端 未结 6 687
长情又很酷
长情又很酷 2020-12-29 07:06

Could you possibly explain how I can get the ServletContext instance in my Application\'s sub-class? Is it possible? I have tried to do it like in

6条回答
  •  自闭症患者
    2020-12-29 07:24

    Don't use @Context in your Application but in a Resource class.

    @Path("/foos")
    public class FooResource {
    
      @Context
      ServletContext ctx;
    
      @GET
      public Response getFoos() {
        return Response.ok().build();
      }
    }
    

提交回复
热议问题