Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable ErrorPageFilter in Spring Boot?

Tags:

I'm creating a SOAP service that should be running on Tomcat.
I'm using Spring Boot for my application, similar to:

@Configuration @EnableAutoConfiguration(exclude = ErrorMvcAutoConfiguration.class) public class AppConfig { } 


My webservice (example):

@Component @WebService public class MyWebservice {      @WebMethod     @WebResult     public String test() {         throw new MyException();     } }  @WebFault public class MyException extends Exception { } 


Problem:
Whenever I throw an exception within the webservice class, the following message is logged on the server:

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


Question:
How can I prevent this?

like image 284
membersound Avatar asked May 11 '15 14:05

membersound


People also ask

What is spring boot ErrorPageFilter?

Class ErrorPageFilterA Servlet Filter that provides an ErrorPageRegistry for non-embedded applications (i.e. deployed WAR files). It registers error pages and handles application errors by filtering requests and forwarding to the error pages instead of letting the server handle them.

What is spring boot2?

Spring Boot 2 brings a set of new starters for different reactive modules. Some examples are WebFlux, and the reactive counterparts for MongoDB, Cassandra or Redis. There are also test utilities for WebFlux. In particular, we can take advantage of @WebFluxTest.


1 Answers

To disable the ErrorPageFilter in Spring Boot (tested with 1.3.0.RELEASE), add the following beans to your Spring configuration:

@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; } 
like image 138
mzc Avatar answered Oct 11 '22 12:10

mzc