How to Remove Whitelabel Error Page

Remove Whitelabel Error Page

The “Whitelabel Error Page” is specific to Spring Boot applications. While Spring Boot uses Java, the error page itself is a feature of the framework and not inherent to the Java language. Here’s how you can remove the Whitelabel Error Page in your Spring Boot application using a custom error page.

Step 1: Create a Custom Error Page

We will create a custom error page to remove Whitelabel Error Page.

  • Simplest Way: Create an HTML file named error.html and place it in your src/main/resources/templates directory (if you’re using Thymeleaf or a similar templating engine). Spring Boot will automatically use this file to display errors.
  • Customizing Specific Errors: Create HTML files for specific error codes (e.g., 404.html, 500. html) and place them in the src/main/resources/templates/error.html. Spring Boot will map the error codes to the corresponding pages.

Example (error.html):

<!DOCTYPE html> 
    <h1>Custom Error Page</h1> 
    <p>Something went wrong. Please try again later.</p> 

Step 2: Changing Default Settings

Spring Boot usually uses files called or application.yml to set up how your app works. You can add or adjust things in these files to change those settings. By default, Spring Boot shows a plain error page when something goes wrong. Let’s change that!

If you’re using Maven, copy and paste these lines into your file:

# Tell Spring Boot where to find our custom templates (error pages)

# What kind of files are our templates (we're using HTML)

# Turn off the plain error page

# Tell Spring Boot where our custom error page is

Add the following line to your file to remove Whitelabel Error Page Not Recommended.


Caution: Disabling the Whitelabel Page will prevent any error information from being displayed to the user, which is not ideal for debugging or user experience.

Step 3: Creating Error Controller class

Let’s make the Controller class, which is like the manager of our project.

Go to the main part of your project, where all the code is.

  • Make a new folder inside it called “controller“. Think of this folder as a special place for our manager.
  • Inside the “controller” folder, make a new file called ““. This file is where we’ll write the instructions for our manager. (You can choose a different name if you want, but we’ll use “” as an example.)

Example ( )

package com.example.demo.controller; 
import org.springframework.boot.web.servlet.error.ErrorController; 
import org.springframework.stereotype.Controller; 
import org.springframework.web.bind.annotation.GetMapping; 
public class ControllerClass implements ErrorController { 
    public String handleError() { 
        return "error_page"; 

Example 2 Advanced Error Handling ( )

public class MyErrorController implements ErrorController {

    public String handleError(HttpServletRequest request) {
        // Get the error status code
        Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
        // Customize error handling based on the status code
        if (statusCode == 404) {
            return "error/404"; // Return a specific view for 404 errors
        } else {
            return "error"; // Return a generic error page

Why We Made the Controller Class

The ControllerClass we created acts like a traffic director for error messages in our app. It uses a special tool called ErrorController to handle those errors.

Inside this class, there’s a function called handleError. It has a tag called @GetMapping with the address “/error”. This means that when an error happens in our app, it goes to this address, and the handleError function takes over. It then shows a page called “error_page” to the user, explaining that something went wrong.

Step 4: Run Your App:

  1. Right-click on the name of your project.
  2. Choose “Run as” from the menu.
  3. Select “Spring Boot App.”

Step 5: What You’ll See with Your Custom Error Page:

Now, instead of seeing the plain Whitelabel Error Page, you’ll see your own custom error page when something goes wrong in your app. This means your changes worked!

Remove Whitelabel Error Page Using Existing ErrorController

For example, your existing ErrorController is

public class IndexController {

    @RequestMapping(value = "/error")
    public String error() {
        return "Error handling";


So, try to change your code to the following:

public class IndexController implements ErrorController{

    private static final String PATH = "/error";

    @RequestMapping(value = PATH)
    public String error() {
        return "Error handling";

    public String getErrorPath() {
        return PATH;

If you are interested in making an Android chat app using Android Studio. Please check out How To Create Chat App in Android Studio