- 问题描述
在使用maven打包(package)springboot项目为war项目后,在本地机器上使用Tomcat跑这个项目,访问资源时出现下面的错误:
o.s.b.w.servlet.support.ErrorPageFilter : Cannot forward to error page
for request [/test] as the response has already been committed. As a
result, the response may have the wrong status code. If your application
is running on WebSphere Application Server you may be able to resolve
this problem by setting com.ibm.ws.webcontainer.invokeFlushAfterService
to false
参考了很多办法,有说在启动类中添加如下代码可以解决:
@Bean
public ErrorPageFilter errorPageFilter() {
return new ErrorPageFilter();
}
@Bean
public FilterRegistrationBean disableSpringBootErrorFilter(ErrorPageFilter filter) {
FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
filterRegistrationBean.setFilter(filter);
filterRegistrationBean.setEnabled(false);
return filterRegistrationBean;
}
还有包括在pom文件中注释掉内嵌的Tomcat依赖的解决办法。
但是我尝试无果。
- 解决办法

引入文件的话,一定要记得将resources目录下的文件引入到类路径下:
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
- 参考引用
https://blog.csdn.net/ljf12138/article/details/117786285
本文详细探讨了在将Spring Boot项目打包为WAR并部署到Tomcat后遇到的404错误,介绍了如何通过配置ErrorPageFilter和确保资源目录引入来解决。同时提供了相关代码示例和解决方案,包括注释掉内嵌Tomcat依赖的方法。
2175

被折叠的 条评论
为什么被折叠?



