Scrivio Interview library
ConceptFoundations7 min read · updated 12 November 2026

What is Spring Boot's Whitelabel Error Page, which component produces it, and how do you replace it with custom HTML pages per status code?

The Whitelabel Error Page is Spring Boot's fallback HTML page for errors. When an error reaches the servlet container, Boot forwards the request to /error, where BasicErrorController returns JSON to API clients and renders the Whitelabel page for browsers when no other error view exists. We replace it by adding pages named after the status code or series, such as templates/error/404.html or static/error/5xx.html, and for more control we implement ErrorViewResolver or customize ErrorAttributes.

Why this question is asked

Every Spring Boot developer has seen the page that says This application has no explicit mapping for /error, so you are seeing this as a fallback. It is useful during development, but it looks unfinished in production and can reveal more than we intend. Interviewers ask about it because it opens the door to how Boot handles errors in general: where the forward to /error comes from, which component builds the response, and which knobs control the details. In this answer, we will follow an error to the Whitelabel page, add custom pages per status code, see how Boot chooses between them, go further with ErrorViewResolver and ErrorAttributes, and decide what details to expose.

1How an Error Reaches the Whitelabel Page

Suppose a browser requests /reports/9 and the controller throws an exception that no handler maps, or a URL matches nothing and Spring MVC sets a 404. In both cases the servlet container sees an error. Spring Boot has registered an error page with the container for all errors, pointing at /error, so the container makes an internal ERROR dispatch to /error. The browser's address bar does not change; this is a forward inside the server.

At /error sits BasicErrorController, part of Boot's ErrorMvcAutoConfiguration. It has two handler methods. One produces text/html and is chosen when the request accepts HTML, which browsers do. The other returns a JSON map for everyone else. The HTML method asks the error view resolvers for a view; if none is found, it uses a view called error, and Boot supplies a default bean of that name that renders the Whitelabel page.

Step throughFrom exception to Whitelabel page
BrowserTomcatBasicErrorControllerError view lookup
GET /reports/9
controller throws, status 500
ERROR dispatch to /error
find error/500 or error/5xx
nothing found
Whitelabel HTML (status 500)

6 messages in order. Play them, or step through them one at a time.

API clients get JSON from the same controller; only HTML requests see the page.

2Adding Custom Pages per Status Code

Boot's DefaultErrorViewResolver looks for a view named after the exact status first, error/404, and then the series, error/4xx. For each name it tries a template (if a template engine such as Thymeleaf is on the classpath) in src/main/resources/templates, and then a static file in the static resource folders, such as src/main/resources/static. The first match wins. So a few files are enough to replace the Whitelabel page entirely.

Java
src/main/resources/
templates/error/404.html <- used for 404 (Thymeleaf, can show the path)
templates/error/5xx.html <- used for 500, 502, 503 ...
static/error/4xx.html <- plain HTML for every other 4xx (400, 403, 405 ...)
<!-- templates/error/404.html -->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<h1>We could not find that page</h1>
<p th:text="'Nothing lives at ' + ${path}">Nothing lives at /reports/9</p>
<p>Status <span th:text="${status}">404</span>, <span th:text="${timestamp}"></span></p>
</body>
</html>
<!-- GET /no-such-page (browser) -> 404 with "Nothing lives at /no-such-page" -->
<!-- GET /reports/9 failing -> 500 with 5xx.html -->
<!-- curl /no-such-page -> 404 JSON, the pages are only for HTML -->

Notice that a template can use the error model: status, error (the reason phrase), path, timestamp, and message or exception if we allow them. A static page cannot, but it needs no template engine. Also notice that the status code of the response stays the real one; the custom page changes only the body, so search engines and monitoring still see a 404 or 500.

3Turning the Whitelabel Page Off

The property server.error.whitelabel.enabled=false removes Boot's default error view. If we have custom pages for the statuses that occur, nothing visible changes. If we do not, the HTML request finds no view, and the user sees whatever the servlet container produces instead, which for Tomcat is its own plain error report. That is rarely nicer than the Whitelabel page, so the property is most useful together with our own pages or our own view named error. To remove Boot's error handling completely, we can exclude ErrorMvcAutoConfiguration, but then we must handle /error ourselves.

4Custom Logic With ErrorViewResolver and ErrorAttributes

File names cover most needs. When the choice of page depends on something else, such as the area of the site, we implement ErrorViewResolver. Boot calls it with the request, the status and the error model, and we return a ModelAndView or null to fall back to the defaults.

Java
@Component
class AreaErrorViewResolver implements ErrorViewResolver {
public ModelAndView resolveErrorView(HttpServletRequest req, HttpStatus status, Map<String, Object> model) {
String path = String.valueOf(model.get("path"));
if (path.startsWith("/admin") && status.is4xxClientError()) {
return new ModelAndView("admin/error", model, status); // admin pages get their own look
}
return null; // everyone else: the normal error/404 lookup
}
}
@Component
class AppErrorAttributes extends DefaultErrorAttributes {
@Override
public Map<String, Object> getErrorAttributes(WebRequest req, ErrorAttributeOptions options) {
Map<String, Object> attrs = super.getErrorAttributes(req, options);
attrs.put("supportId", MDC.get("traceId")); // shown on the page and in the JSON
return attrs;
}
}

Notice the difference between the two. ErrorViewResolver chooses which page to render. ErrorAttributes decides what data exists, and it feeds both the HTML pages and the JSON body, so a field added there, like a support id the user can quote, appears for browsers and API clients alike.

5Deciding What Details to Expose

By default Boot keeps error responses lean: the message, the stack trace, the exception class and binding errors are not included. Each has a property. server.error.include-message, server.error.include-binding-errors and server.error.include-stacktrace accept never, always or on-param, where on-param includes the detail only when the request has a parameter such as ?trace=true. server.error.include-exception is true or false. Since Spring Boot 2.3 the defaults have been never or false, and they should stay that way in production, because messages and stack traces can reveal SQL, file paths, library versions and data.

A common and safe pattern is to turn details on in a dev profile only, and in production show a friendly page with a support id that links the user's report to the full error in our logs.

Error detail properties
PropertyDefaultProduction advice
server.error.include-messagenevernever (or only safe messages)
server.error.include-binding-errorsneveruse your own validation format
server.error.include-stacktracenevernever
server.error.include-exceptionfalsefalse
server.error.whitelabel.enabledtruefalse once custom pages exist
server.error.path/errorkeep unless it clashes
Details are for logs; pages are for people.

6Follow-up questions

Why do API clients not see my custom HTML pages?

Because BasicErrorController chooses by content negotiation. A request that accepts text/html goes to the HTML method and gets our pages; a request that accepts JSON gets the JSON map. For REST APIs we usually return problem details from a controller advice, so most errors never reach /error at all.

Does a custom error page work for exceptions handled by @ControllerAdvice?

No, and that is expected. If an @ExceptionHandler returns a response, the error never reaches the container, so there is no forward to /error. Error pages only apply to errors that escape Spring MVC or that are reported with response.sendError(), such as the 404 for an unknown URL.

Can I test the error pages with MockMvc?

Only partly. MockMvc does not perform the container's error dispatch, so a request to an unknown URL returns the status without our page. We can call /error directly with the error request attributes set, but a test against a running server, using @SpringBootTest with a random port, is the reliable way to see the page a browser gets.

7Conclusion

In this answer, we saw that the Whitelabel page is Boot's fallback error view, rendered by BasicErrorController after the container forwards an error to /error, while API clients get JSON from the same controller. We replaced it with pages under templates/error or static/error named after the status code or its series, saw that server.error.whitelabel.enabled=false removes the default view and leaves the container's page if we provide none, used ErrorViewResolver to choose pages with custom logic and ErrorAttributes to change the data, and kept details such as messages and stack traces off in production with the server.error.include-* properties.

What to say in the interviewAbout 80 seconds aloud

Open with

The Whitelabel Error Page is what Spring Boot shows a browser when an error has no better page. When an exception escapes Spring MVC, or something calls sendError, like the 404 for an unknown URL, the servlet container forwards to /error, because Boot registers that as the error page.

Then, if they want more

There, BasicErrorController from ErrorMvcAutoConfiguration handles it: for requests that accept HTML it looks for an error view, and if there is none it renders Boot's default view called error, which is the Whitelabel page; for other clients it returns JSON with timestamp, status, error and path.

To replace it, I add files named after the status: templates/error/404.html if I use Thymeleaf, or static/error/404.html, and series pages like 5xx.html. Boot's DefaultErrorViewResolver tries the exact code first, then the series, templates before static files. The status code itself stays correct.

If I need logic, like a different page for /admin, I implement ErrorViewResolver; if I want to change the data, like adding a support id, I extend DefaultErrorAttributes, which feeds both HTML and JSON. server.error.whitelabel.enabled=false removes the default page, so then I need my own pages or the container's page shows. And I keep include-message, include-stacktrace and include-binding-errors at never in production.

About this answer

Last updated
12 November 2026
Versions it names
Spring Boot 2.3
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What is Spring Boot's Whitelabel Error Page, which component produces it, and how do you...": https://scrivio-interview-library.netlify.app/spring-boot/error-handling/54f05d37af/