gpt4 book ai didi

找不到 javax.servlet.http.HttpServletResponse.getStatus()

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:53:15 24 4
gpt4 key购买 nike

我正在使用嵌入式 Jetty 服务器,部署 Jersey REST api,我正在尝试使用 log4J 记录错误。当发生错误时,例如找不到 URL,并且控制台日志显示以下错误:

java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getStatus()I
at org.eclipse.jetty.server.handler.ErrorHandler.doError(ErrorHandler.java:142)
at org.eclipse.jetty.server.handler.ErrorHandler.handle(ErrorHandler.java:78)
at org.eclipse.jetty.server.Response.sendError(Response.java:655)
at org.glassfish.jersey.servlet.internal.ResponseWriter.callSendError(ResponseWriter.java:225)
at org.glassfish.jersey.servlet.internal.ResponseWriter.commit(ResponseWriter.java:194)
at org.glassfish.jersey.server.ContainerResponse.close(ContainerResponse.java:413)
at org.glassfish.jersey.server.ServerRuntime$Responder.release(ServerRuntime.java:810)
at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:515)
at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:334)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)
at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:841)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:535)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.Server.handle(Server.java:564)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:317)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:251)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:110)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
at org.eclipse.jetty.util.thread.Invocable.invokePreferred(Invocable.java:128)
at org.eclipse.jetty.util.thread.Invocable$InvocableExecutor.invoke(Invocable.java:222)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:294)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.produce(EatWhatYouKill.java:126)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:673)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:591)
at java.lang.Thread.run(Thread.java:748)

有我的依赖项:

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>api-ejb</artifactId>
<version>${project.parent.version}</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1-m09</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.19</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>6.4.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.6.v20170531</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>9.4.6.v20170531</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-server</artifactId>
<version>2.26-b02</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<version>2.26-b01</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
</dependency>
</dependencies>

和服务器初始化代码:

ServletContextHandler servletContextHandler = new ServletContextHandler();
ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.register(MultiPartFeature.class);
resourceConfig.register(GsonMessageBodyHandler.class);
resourceConfig.register(PrivateAPI.class);
resourceConfig.register(MalformedURLExceptionMapper.class);
ServletContainer sc = new ServletContainer(resourceConfig);
ServletHolder holder = new ServletHolder(sc);
servletContextHandler.addServlet(holder, "/*");


Server server = new Server(new InetSocketAddress(args[0], Integer.parseInt(args[1])));
HandlerCollection handlerCollection = new HandlerCollection();

handlerCollection.setHandlers(new Handler[] {servletContextHandler, new RequestLogHandler(), new DefaultHandler()});
server.setHandler(handlerCollection);
server.start();
server.join();

最佳答案

您的项目中有一个非常古老的 servlet-api jar。

javax.servlet.http.HttpServletResponse#getStatus()在 Servlet 3.0 中加入

添加以下内容:

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>

转储您的依赖项并验证您没有存在多个版本的 servlet-api jar(这很常见,因为 servlet-api jar 的 maven 坐标空间在过去 10 年中发生了几次变化)

$ mvn dependency:tree

关于找不到 javax.servlet.http.HttpServletResponse.getStatus(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44730096/

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