Java Dropwizard升级HttpServletRequest请求空指针异常
我已将dropwizard版本从1.3.12升级到2.0.12。 再次运行我的应用程序后,HttpServletRequest中出现空指针异常。 下面是示例代码Java Dropwizard升级HttpServletRequest请求空指针异常,java,servlets,nullpointerexception,dropwizard,Java,Servlets,Nullpointerexception,Dropwizard,我已将dropwizard版本从1.3.12升级到2.0.12。 再次运行我的应用程序后,HttpServletRequest中出现空指针异常。 下面是示例代码 import javax.servlet.http.HttpServletRequest; public class myClass{ @Context private HttpServletRequest request; @GET @Path("/authent
import javax.servlet.http.HttpServletRequest;
public class myClass{
@Context
private HttpServletRequest request;
@GET
@Path("/authenticate")
@Produces(MediaType.TEXT_HTML)
public Response getAuthentication(@QueryParam("myParam") String myParam) {
System.out.println(request);
}
}
正如您所知,我已经从代码中删除了额外的位以使其变得简单。
有什么建议为什么要将HttpServletRequestas设置为null?dropwizard 1.3.12版运行良好。将带有字段上下文注入的资源实例迁移到dropwizard 2.0涉及将字段推送到所需端点的参数中,因此您的类将如下所示:
public class MyClass {
@GET
@Path("/authenticate")
@Produces(MediaType.TEXT_HTML)
public Response getAuthentication(final @Context HttpServletRequest request,
@QueryParam("myParam") String myParam) {
System.out.println(request);
return Response.ok().build();
}
}
见