springboot项目打包后部署外部Tomcat出现ErrorPageFilter异常--处理方案

前言:

        近段时间,将项目部署到测试环境供测试人员进行测试,结果一天后看日志,发现日志居然10多M了。唉,苦逼的去撸日志,结果发现一大堆关于JS的错误。初看还真的以为是js的错误。后来认真看才发现,开始了问题排查。国内的百度--真心垃圾,找的都是废话,也可能是我的搜索不对。逼得我五好青年科学上网,寻求方案。

 

    注:这个错误其实不用理的,因为不会影响到服务器的正常运行,但是这种错误还是恶心了一把我们找日志定位问题

 

错误如下:(部分错误)

27-Nov-2018 14:23:36.489 严重 [http-nio-8080-exec-6] org.springframework.boot.web.servlet.support.ErrorPageFilter.handleCommittedResponse Cannot forward to error page for request [/zhst/static/jquery.min.js] 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
 org.apache.catalina.connector.ClientAbortException: java.io.IOException: Connection reset by peer
	at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:356)
	at org.apache.catalina.connector.OutputBuffer.flushByteBuffer(OutputBuffer.java:808)
	at org.apache.catalina.connector.OutputBuffer.append(OutputBuffer.java:713)
	at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:391)
	at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:369)
	at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:96)
	at org.springframework.util.StreamUtils.copy(StreamUtils.java:140)

 

问题出现的原因:

    先看看错误:

org.springframework.boot.web.servlet.support.ErrorPageFilter.handleCommittedResponse Cannot forward to error page for request [/zhst/static/jquery.min.js] 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

     翻译一下:

大致的意思是说,我们请求这个链接或者资源时,已经提前被响应了,所以在此提交会爆出这个奇妙的异常。有趣的是,错误信息还给了我们解决方案哦。虽然我没看懂~!

 为什么会出现这个问题,接下来我们开始排查之路

     原因:

  (1)检查程序中response响应的对象写的位置是否正确,会引起这个异常。

  (2)用户在请求某个资源或链接时,由于用户网速真心感人,可能用户会提前断掉请求(关闭页面,刷新也是有可能的)

    

解决方案:

    (1)检查你的代码 没问题的话就抛弃这个

 

    (2)在springboot启动类中加入如下代码:(当然,你也可以另外起个配置类,反正我懒,就写这了)

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

 

总结:

          加完后,让组长重新部署,接下来就屁颠屁颠去打游戏啦。一天后在来看,日志才几百K的时候(测试使用的正常水平),心情舒爽,顺带来记录一下这个错误。

 

 

你可能感兴趣的:(错误总结)