Spring Boot shows the Whitelabel Error Page instead of your endpoint
Fix it fast
Most common cause, 1 of 3The 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.
// 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;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.
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.
curl -s -i http://localhost:8080/helloThen find the line you see in this list and open its fix:
- 1The controller is outside the main application's package
Every endpoint you wrote returns status 404, and a breakpoint or log line inside the controller never fires - 2A @Controller method returns a String that Spring treats as a view name
The method runs (its log line prints), yet the browser still lands on the Whitelabel page instead of showing the returned text - 3The URL or HTTP method does not match any mapping
Other 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 PageThis 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.
grep -rn "^package" src/main/java | sort -t: -k3Fix
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.
// 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.
curl -s -o /dev/null -w "%{http_code}\n" http://localhost:8080/helloConfirmed by docs.spring.io
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.
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.
@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.
curl -s http://localhost:8080/helloConfirmed by docs.spring.io
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.
grep -rn -E "@(Get|Post|Put|Delete|Patch|Request)Mapping" src/main/java
curl -s -i -X POST http://localhost:8080/ordersFix
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.
@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.
curl -s -i -X POST -H "Content-Type: application/json" -d '{}' http://localhost:8080/api/ordersConfirmed by docs.spring.io
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.