Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

Spring Boot shows the Whitelabel Error Page instead of your endpoint

Your error

Whitelabel Error Page2 more lines it can show

Fix it fast

Most common cause, 1 of 3

The controller is outside the main application's package

Move the main class to the root package, above every controller, service and repository, or move the controllers below it.

Fix
// com/example/shop/ShopApplication.java  <- root package
package com.example.shop;

// com/example/shop/web/HelloController.java  <- below the root
package com.example.shop.web;
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Whitelabel Error Page (no explicit mapping for /error) is Spring Boot's fallback view; the status line under it is the clue. Usually the controller sits outside the main class's package and is never scanned, a @Controller returns a view name instead of a body, or the URL or HTTP method misses the mapping. Applies to Spring Boot 4.2.

  • Applies to Spring Boot 4.2.0 (also 4.1.3 and 4.0.10), Spring Web MVC (spring-boot-starter-webmvc 4.2.0)
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Ask the same URL from the command line. A machine client gets the error as JSON, with the status and the path that failed. Every endpoint returning 404 points to cause 1; a 404 or 500 from a method you know runs points to cause 2; one URL or one method failing while its neighbours work points to cause 3.

Run this first
curl -s -i http://localhost:8080/hello

Then find the line you see in this list and open its fix:

  1. 1The controller is outside the main application's packageEvery endpoint you wrote returns status 404, and a breakpoint or log line inside the controller never fires
  2. 2A @Controller method returns a String that Spring treats as a view nameThe method runs (its log line prints), yet the browser still lands on the Whitelabel page instead of showing the returned text
  3. 3The URL or HTTP method does not match any mappingOther endpoints in the same controller work; only one path, or the same path called with another method, returns the Whitelabel page

What does the error look like?

  • Whitelabel Error Page
  • This application has no explicit mapping for /error, so you are seeing this as a fallback.
  • There was an unexpected error (type=Not Found, status=404).

Cause 1 of 3

The controller is outside the main application's package

You seeEvery endpoint you wrote returns status 404, and a breakpoint or log line inside the controller never fires

Check

When a Spring Boot app shows the Whitelabel page with status 404 for all its endpoints, check where the controller lives. Spring Boot's guide says the @SpringBootApplication class sets the base package for component scanning, so a controller in a sibling or parent package is never registered and no mapping exists for its URLs.

Check
grep -rn "^package" src/main/java | sort -t: -k3

Fix

Move the main class to the root package, above every controller, service and repository, or move the controllers below it. Keep the application out of the default package.

Fix
// com/example/shop/ShopApplication.java  <- root package
package com.example.shop;

// com/example/shop/web/HelloController.java  <- below the root
package com.example.shop.web;

Verify

Restart the app. The same curl now returns 200 with your response body.

Verify
curl -s -o /dev/null -w "%{http_code}\n" http://localhost:8080/hello

Confirmed by docs.spring.io

Did this fix it?

Cause 2 of 3

A @Controller method returns a String that Spring treats as a view name

You seeThe method runs (its log line prints), yet the browser still lands on the Whitelabel page instead of showing the returned text

Check

In a class marked @Controller, a String return value is a view name that a ViewResolver must turn into a template. With no template engine or no matching template, the request ends in an error, and Spring Boot renders the Whitelabel page for it.

Check
grep -rl "@Controller" src/main/java | xargs grep -n "public String"

Fix

For a JSON or text API, use @RestController, which is meta-annotated with @Controller and @ResponseBody, so return values are written to the response. For HTML pages, add a template engine and a template whose name matches the returned string.

Fix
@RestController
public class HelloController {
    @GetMapping("/hello")
    public String hello() {
        return "hello";   // now the body, not a view name
    }
}

Verify

curl prints hello with status 200 instead of the error JSON.

Verify
curl -s http://localhost:8080/hello

Confirmed by docs.spring.io

Did this fix it?

Cause 3 of 3

The URL or HTTP method does not match any mapping

You seeOther endpoints in the same controller work; only one path, or the same path called with another method, returns the Whitelabel page

Check

Spring MVC matches a request by URL, HTTP method, parameters, headers and media types. A browser address bar always sends GET, so it cannot reach a @PostMapping, and a typo or missing class-level @RequestMapping prefix changes the path the method answers on.

Check
grep -rn -E "@(Get|Post|Put|Delete|Patch|Request)Mapping" src/main/java
curl -s -i -X POST http://localhost:8080/orders

Fix

Call the endpoint with the method and full path its annotations declare, including any class-level prefix, or change the annotation to match how clients really call it.

Fix
@RestController
@RequestMapping("/api")
public class OrderController {
    @PostMapping("/orders")   // full path: POST /api/orders
    public Order create(@RequestBody Order order) { ... }
}

Verify

The request with the declared method and path returns the expected status.

Verify
curl -s -i -X POST -H "Content-Type: application/json" -d '{}' http://localhost:8080/api/orders

Confirmed by docs.spring.io

Did this fix it?

How do I stop it coming back?

  • Generate new projects with the main class in the root package and add every new package under it.
  • Use @RestController for API classes and keep @Controller for classes that render templates.
  • Add a test per endpoint with MockMvc or a real HTTP call, so a missing mapping fails the build instead of reaching a browser.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: Dispatch Pro.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.