Quick revision
The short answer
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.
What to remember
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.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
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.
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.
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.
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.
| Property | Default | Production advice |
|---|---|---|
server.error.include-message | never | never (or only safe messages) |
server.error.include-binding-errors | never | use your own validation format |
server.error.include-stacktrace | never | never |
server.error.include-exception | false | false |
server.error.whitelabel.enabled | true | false once custom pages exist |
server.error.path | /error | keep unless it clashes |
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.
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.
- Official documentation
- Spring Framework reference, Spring Web MVC
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/