gpt4 book ai didi

java - 空 HttpServletRequest

转载 作者:太空宇宙 更新时间:2023-11-04 12:29:29 30 4
gpt4 key购买 nike

我正在 Spring MVC 上 Swagger 玩,运行本地 jetty ,由于某种原因得到一个 null HttpServletRequest,至少可以说这很奇怪。

这是完整的堆栈跟踪:

java.lang.IllegalArgumentException: HttpServletRequest must not be null
at org.springframework.util.Assert.notNull(Assert.java:115)
at org.springframework.http.server.ServletServerHttpRequest.<init>(ServletServerHttpRequest.java:72)
at org.springframework.web.servlet.support.ServletUriComponentsBuilder.initFromRequest(ServletUriComponentsBuilder.java:120)
at org.springframework.web.servlet.support.ServletUriComponentsBuilder.fromContextPath(ServletUriComponentsBuilder.java:74)
at org.springframework.web.servlet.support.ServletUriComponentsBuilder.fromServletMapping(ServletUriComponentsBuilder.java:88)
at springfox.documentation.swagger2.web.HostNameProvider.componentsFrom(HostNameProvider.java:35)
at springfox.documentation.swagger2.web.Swagger2Controller.getDocumentation(Swagger2Controller.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:820)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:401)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450)
at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:230)
at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
at org.mortbay.jetty.Server.handle(Server.java:326)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:928)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:549)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:212)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410)
at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

为什么在这种情况下我会得到 null HttpServletRequest?我只是通过浏览器发送一个简单的请求,没什么花哨的。

编辑 1此后我尝试使用带有嵌入式 jetty 的 Maven cargo 插件,它似乎有效。我仍然不知道为什么 jetty 插件本身会出现此错误。这是用于记录的版本:

        <groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.26</version>

最佳答案

好的,所以问题是我使用的jetty版本(6.1.26)。更新到 9.3.10.v20160621 或使用带有 8+ 嵌入式 jetty 的 cargo 插件为我解决了这个问题。但我不确定为什么会出现这个问题。

关于java - 空 HttpServletRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38003656/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com