我正在创建一个应该在tomcat上运行的soap服务.
我正在为我的应用程序使用 spring-boot,类似于:
我正在为我的应用程序使用 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; }