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

前端之家收集整理的这篇文章主要介绍了java – 如何在spring-boot中禁用ErrorPageFilter?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在创建一个应该在tomcat上运行的soap服务.
我正在为我的应用程序使用 spring-boot,类似于:
@Configuration
@EnableAutoConfiguration(exclude = ErrorMvcAutoConfiguration.class)
public class AppConfig {
}
@H_301_5@我的webservice(示例):

@Component
@WebService
public class MyWebservice {

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

@WebFault
public class MyException extends Exception {
}
@H_301_5@问题:无论何时在webservice类中引发异常,服务器上都会记录以下消息:

@H_301_5@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

@H_301_5@问题:我该如何防范?

解决方法

要在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;
}

猜你在找的Java相关文章