加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 如何在spring-boot中禁用ErrorPageFilter?

发布时间:2020-12-14 05:09:57 所属栏目:Java 来源:网络整理
导读:我正在创建一个应该在tomcat上运行的soap服务. 我正在为我的应用程序使用 spring-boot,类似于: @Configuration@EnableAutoConfiguration(exclude = ErrorMvcAutoConfiguration.class)public class AppConfig {} 我的webservice(示例): @Component@WebServi
我正在创建一个应该在tomcat上运行的soap服务.
我正在为我的应用程序使用 spring-boot,类似于:
@Configuration
@EnableAutoConfiguration(exclude = ErrorMvcAutoConfiguration.class)
public class AppConfig {
}

我的webservice(示例):

@Component
@WebService
public class MyWebservice {

    @WebMethod
    @WebResult
    public String test() {
        throw new MyException();
    }
}

@WebFault
public class MyException extends Exception {
}

问题:无论何时在webservice类中引发异常,服务器上都会记录以下消息:

ErrorPageFilter: Cannot forward to error page for request
[/services/MyWebservice] 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

问题:我该如何防范?

解决方法

要在Spring Boot中禁用ErrorPageFilter(使用1.3.0.RELEASE进行测试),请将以下bean添加到Spring配置中:
@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;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读