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

我正在创建一个应该在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;
}

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...