membersound membersound - 4 years ago 1026
Java Question

How to disable ErrorPageFilter in spring-boot?

I'm creating a

service that should be running on a tomcat.
I'm using
for my application, similar to:

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

My webservice (example):

public class MyWebservice {

public String test() {
throw new MyException();

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 to false

Question: how can I prevent this?

mzc mzc
Answer Source

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

public ErrorPageFilter errorPageFilter() {
    return new ErrorPageFilter();

public FilterRegistrationBean disableSpringBootErrorFilter(ErrorPageFilter filter) {
    FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
    return filterRegistrationBean;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download