使用Tomcat提供静态资源:响应外观.setContentLengthLong(J)V是抽象的

5ktev3wc  于 2022-11-24  发布在  其他
关注(0)|答案(1)|浏览(202)

我有一个通过Tomcat版本8提供的SpringBoot Web服务。使用SpringBoot API是正常的,但请求静态资源会导致以下错误:

[ERROR] 2022-09-27 11:38:00,537 [http-bio-172.17.0.19-8080-exec-1]  [] - Servlet.service() for servlet [dispatcherServlet] threw exception -org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/].[dispatcherServlet]
java.lang.AbstractMethodError: Method org/apache/catalina/connector/ResponseFacade.setContentLengthLong(J)V is abstract
        at org.apache.catalina.connector.ResponseFacade.setContentLengthLong(ResponseFacade.java) ~[catalina.jar:7.0.99]
        at javax.servlet.ServletResponseWrapper.setContentLengthLong(ServletResponseWrapper.java:135) ~[javax.servlet-api-4.0.1.jar:4.0.1]
        at org.springframework.http.server.ServletServerHttpResponse.writeHeaders(ServletServerHttpResponse.java:130) ~[spring-web-5.3.9.jar:5.3.9]
        at org.springframework.http.server.ServletServerHttpResponse.getBody(ServletServerHttpResponse.java:96) ~[spring-web-5.3.9.jar:5.3.9]
        at org.springframework.http.converter.ResourceHttpMessageConverter.writeContent(ResourceHttpMessageConverter.java:137) ~[spring-web-5.3.9.jar:5.3.9]
        at org.springframework.http.converter.ResourceHttpMessageConverter.writeInternal(ResourceHttpMessageConverter.java:129) ~[spring-web-5.3.9.jar:5.3.9]
        at org.springframework.http.converter.ResourceHttpMessageConverter.writeInternal(ResourceHttpMessageConverter.java:45) ~[spring-web-5.3.9.jar:5.3.9]
        at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:227) ~[spring-web-5.3.9.jar:5.3.9]
        at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:555) ~[spring-webmvc-5.3.9.jar:5.3.9]
        at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:52) ~[spring-webmvc-5.3.9.jar:5.3.9]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1064) ~[spring-webmvc-5.3.9.jar:5.3.9]
        ...

有没有办法解决这个问题?我已经试过把嵌入的Tomcat从pom.xml中排除,导致编译错误,把Tomcat的server.xml中的文档内容根配置到路径,也导致了上面的错误。

ycl3bljg

ycl3bljg1#

我设法通过回到Sping Boot 版本2. 3. 9. RELEASE来解决这个问题。

相关问题