Get ServletContext in Application

前端 未结 6 705
长情又很酷
长情又很酷 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:31

    Since Jersey 2.5, ServletContext can be injected directly in constructor: https://java.net/jira/browse/JERSEY-2184

    public class MyApplication extends ResourceConfig {
        public MyApplication(@Context ServletContext servletContext) {
           // TODO
        }
    }
    

提交回复
热议问题