0
0
SpringbootDebug / FixBeginner · 3 min read

How to Fix Whitelabel Error Page in Spring Boot Quickly

The Whitelabel Error Page in Spring Boot appears when no custom error page or controller handles the error. To fix it, create a controller or add an index.html in src/main/resources/templates or static folder, or configure error handling properly.
🔍

Why This Happens

The Whitelabel Error Page appears because Spring Boot cannot find a matching controller or view for the requested URL. It shows a default error page when no custom error page or handler is defined. This usually happens when the URL path is incorrect or the controller method is missing.

java
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MyController {

    // Missing mapping for root or requested path
}
Output
<html> <head><title>Error</title></head> <body> <h1>Whitelabel Error Page</h1> <p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p> <p>There was an unexpected error (type=Not Found, status=404).</p> </body> </html>
🔧

The Fix

To fix the Whitelabel Error Page, add a controller method mapped to the requested URL or add a static index.html in src/main/resources/static. This tells Spring Boot what to show instead of the default error page.

java
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MyController {

    @GetMapping("/")
    public String home() {
        return "Hello, Spring Boot!";
    }
}
Output
Hello, Spring Boot!
🛡️

Prevention

Always define controller mappings for your URLs or provide static HTML pages in the static or templates folders. Use Spring Boot's ErrorController to customize error pages. Test your routes early to catch missing mappings.

⚠️

Related Errors

  • 404 Not Found: Happens when URL mapping is missing; fix by adding controller methods.
  • 500 Internal Server Error: Caused by exceptions in code; fix by handling exceptions properly.
  • Whitelabel Error Page with 403 Forbidden: Usually a security config issue; fix by adjusting Spring Security settings.

Key Takeaways

The Whitelabel Error Page means no controller or view matches the request URL.
Add controller methods or static HTML files to fix missing mappings.
Customize error handling with Spring Boot's ErrorController interface.
Test your application routes early to avoid unexpected errors.
Check security settings if you see Whitelabel errors with 403 status.