java.lang.NoSuchMethodError:javax.servlet.http.HttpServletRequest.startAsync

前端之家收集整理的这篇文章主要介绍了java.lang.NoSuchMethodError:javax.servlet.http.HttpServletRequest.startAsync前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
知道为什么我在运行时遇到这个错误吗?
我正在尝试在Jetty上部署AsyncServlet.
  1. java.lang.NoSuchMethodError: javax.servlet.http.HttpServletRequest.startAsync(Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;)Ljavax/servlet/AsyncContext;
  2. at my.server.SlowServlet.doGet(SlowServlet.java:16)
  3. at javax.servlet.http.HttpServlet.service(HttpServlet.java:705)
  4. at javax.servlet.http.HttpServlet.service(HttpServlet.java:814)
  5. at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:547)
  6. at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:480)
  7. at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
  8. at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:520)
  9. at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:227)
  10. at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:941)
  11. at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:409)
  12. at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:186)
  13. at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:875)
  14. at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
  15. at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:250)
  16. at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:149)
  17. at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:110)
  18. at org.eclipse.jetty.server.Server.handle(Server.java:345)
  19. at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:441)
  20. at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:919)
  21. at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:582)
  22. at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:218)
  23. at org.eclipse.jetty.server.AsyncHttpConnection.handle(AsyncHttpConnection.java:51)
  24. at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:586)
  25. at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:44)
  26. at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:598)
  27. at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:533)
  28. at java.lang.Thread.run(Thread.java:680)

我在我的pom.xml中有以下Maven依赖项

  1. <dependency>
  2. <groupId>org.eclipse.jetty</groupId>
  3. <artifactId>jetty-server</artifactId>
  4. <version>${jettyVersion}</version>
  5. </dependency>
  6.  
  7.  
  8. <dependency>
  9. <groupId>org.eclipse.jetty</groupId>
  10. <artifactId>jetty-servlet</artifactId>
  11. <version>${jettyVersion}</version>
  12. </dependency>
  13.  
  14. <dependency>
  15. <groupId>org.eclipse.jetty</groupId>
  16. <artifactId>jetty-servlets</artifactId>
  17. <version>${jettyVersion}</version>
  18. </dependency>
  19.  
  20.  
  21. <dependency>
  22. <groupId>org.eclipse.jetty</groupId>
  23. <artifactId>jetty-webapp</artifactId>
  24. <version>${jettyVersion}</version>
  25. </dependency>

解决方法

我猜你的服务器使用的是Servlet规范的错误版本. AsyncContext仅在Servlet规范v 3.0之后可用.您可能在开发环境中拥有正确的版本,但您的服务器使用过时的api版本,因此运行时出错.

猜你在找的Java相关文章