我正在玩弄 JAX-RS,部署在 Tomcat 上。基本上是:
@Path("/hello")
@Produces({"text/plain"})
public class Hellohandler {
@GET
public String hello() {
return "Hello World";
}
}
有什么方法可以在我的 JAX-RS 资源中获取 ServletContext
吗?
最佳答案
此外,@Resource
注释可能不起作用。试试这个
@javax.ws.rs.core.Context
ServletContext context;
在您点击服务方法之前不会发生注入(inject)
public class MyService {
@Context ServletContext context;
public MyService() {
print("Constructor " + context); // null here
}
@GET
@Path("/thing") {
print("in wizard service " + context); // available here
关于tomcat - 在 JAX-RS 资源中获取 ServletContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1814517/