尽管没有使用Singleton范围,@ Context返回代理而不是HttpServletRequest

时间:2017-03-21 11:36:30

标签: jersey guice embedded-jetty

尝试访问request.getServletContext()时找不到方法错误,HttpServletRequest也始终是代理对象

资源类

// also tried @RequestScoped
@Path("/res")
public class ProdController {
    @Context
    private HttpServletRequest request;



    @GET
    @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
    public Response getProductList() {
            System.out.println(request.getClass());
            // this always prints class com.sun.proxy.$Proxy34
            // when I try to access request.getServletContext(); it always shows method not found error

            // more code goes here
    }

活页夹模块

public class ApplicationBinderModule extends ServletModule {
    @Override
    protected void configureServlets() {
        bind(ProdController.class);
        serve("/*").with(GuiceContainer.class);

    }
}

0 个答案:

没有答案