SpringBoot项目在使用Maven打包war中遇到的问题

本文详细探讨了在将Spring Boot项目打包为WAR并部署到Tomcat后遇到的404错误,介绍了如何通过配置ErrorPageFilter和确保资源目录引入来解决。同时提供了相关代码示例和解决方案,包括注释掉内嵌Tomcat依赖的方法。
  1. 问题描述
    在使用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依赖的解决办法。

但是我尝试无果。

  1. 解决办法
    在这里插入图片描述
    引入文件的话,一定要记得将resources目录下的文件引入到类路径下:
<resource>
	<directory>src/main/resources</directory>
	<includes>
		<include>**/*.*</include>
	</includes>
</resource>
  1. 参考引用

https://blog.csdn.net/ljf12138/article/details/117786285

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

孤鸟的歌

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值