This post will discuss how to disable the Whitelabel Error Page in Spring Boot.

We know that Spring Boot displays a Whitelabel error page if you encounter a server error. A typical Whitelabel error page looks like below in the client browser:

Whitelabel Error Page
This application has no explicit mapping for /error, so you see this as a fallback.
 
Tue Dec 25 14:23:07 IST 2018
There was an unexpected error (type=Not Found, status=404).
No message available

 
There are several ways to switch the default Whitelabel error page off in Spring Boot and replace it with your servlet container’s error page. We can also add your own error page rather than disabling it completely and send the client a sensible response with the right error code.

1. Property file

If we set server.error.whitelabel.enabled property to false in application.properties or application.yml, it turns the default error page off. This will cause the servlet container’s error pages to show up instead. For instance, the embedded tomcat container now displays ‘HTTP Status 404 – Not Found’ error message.

2. Excluding ErrorMvcAutoConfiguration bean

We can also disable the ErrorMvcAutoConfiguration bean inside the main class to remove the Whitelabel error page. This will also restore the default error page of the servlet container that you are using.

 
We can also do this in the application properties/YAML file.

application.properties

application.yml

 
Note that all the above-mentioned methods still displays the servlet container’s error page. The recommended approach is to create a View that resolves with a name of error or a @Controller that handles the /error path. This is discussed here.

That’s all about disabling Whitelabel Error Page in Spring Boot.