How to Disable the Whitelabel Error Page in Spring Boot

In this post, we will see 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 client browser:

 

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing 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 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 turn the default error page off. This will cause servlet container’s error pages to show up instead. For instance, embedded tomcat container now displays the below error message.

HTTP Status 404 – Not Found

 

2. Excluding ErrorMvcAutoConfiguration bean

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

 

 
This can be also done in application properties/YAML file.

 

application.properties

 

application.yml

 

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

 
1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)

Loading...

Thanks for reading.

Please use our online compiler to post code in comments. To contribute, get in touch with us.
Like us? Please spread the word and help us grow. Happy coding 🙂
 


Leave a Reply

avatar
  Subscribe  
Notify of