How to solve whitelabel error page when using springboot and jsp
When using springboot mvc , you may encounter this error:
You visit: http://localhost:8080/ , it should ok, but the browser display an error page like this:
- SpringBoot 1.x and 2.x
- Java 1.8+
- Maven 3.3+
3. How to replay this error?
3.1 The project layout
I have a springboot project , just for test the springboot and mvc:
It’s very simple.
3.2 The problem
when I run it, and visit http://localhost:8080, I got this:
4. How to debug this problem?
Just search the keywords Whitelabel Error Page from the spring project at github , you can get to the ErrorMvcAutoConfiguration, which has this code:
Notice the @ConditionalOnProperty annotation, it means that:
- If server.error.whitelabel.enabled is not defined,condition match
- Else if server.error.whitelabel.enabled is true,condition match
5. How to solve this problem?
5.1 Disable whitelabel error page with property
According to the above inspection of the spring source code, the solution to hide the Whitelabel Error Page is :
In your src/main/resources/application.properties, just add this line:
5.2 Disable whitelabel error page with annotation
You can see that the WhitelabelErrorViewConfiguration class is loaded by ErrorMvcAutoConfiguration, which is a @Configuration class, so ,you can exclude it in your springboot main class like this:
The WhiteLabel Error Page issue is a nightmare for newbies of springboot. After reading this article, you can find that the key point is to find why spring show this page and where the code is, and then the solution is simple.