spring boot项目中ErrorPage错误问题

1.问题描述

在springboot编程中,访问某一页面地址时,有时候会遇到这样的错误提示:

[org.springframework.boot.web.support.ErrorPageFilter:208] - Cannot forward to error page for request [/user] 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

这个问题在我的项目中并不是每次都会出现,具体原因尚不清楚。

2.解决方法

在项目启动类中添加如下配置:

    @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;
    }

猜你喜欢

转载自blog.csdn.net/rhx_1989/article/details/81091990