Quick revision
The short answer
Spring Boot's server.error.include-stacktrace controls whether /error responses contain the stack trace, and its default is never. The related properties server.error.include-message and server.error.include-binding-errors control the message and the validation errors, with server.error.include-exception for the exception class name. Most likely someone set include-stacktrace to always or on_param, through a profile, an environment variable or a config server, or DevTools, which sets verbose defaults for development, is active in production.
What to remember
In this answer, we traced production stack traces back to Spring Boot's /error output. server.error.include-stacktrace controls the trace and defaults to never, while include-message, include-binding-errors and include-exception control the other details. A value of always or on_param, set through a profile, an environment variable or a config server, or DevTools running where it should not, explains the change. We found the source with the Actuator env endpoint, set never explicitly and added a test that requests trace=true and asserts no trace comes back.
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.
Spring Boot's server.error.include-stacktrace controls whether /error responses contain the stack trace, and its default is never. The related properties server.error.include-message and server.error.include-binding-errors control the message and the validation errors, with server.error.include-exception for the exception class name. Most likely someone set include-stacktrace to always or on_param, through a profile, an environment variable or a config server, or DevTools, which sets verbose defaults for development, is active in production.
Why this question is asked
Stack traces in production responses are a security problem, not a cosmetic one: they reveal framework versions, class names and sometimes SQL, which helps an attacker plan their next request. When they appear suddenly, something changed in configuration, and the fastest way to find it is to know which properties control the output and where their values can come from. Interviewers ask this debugging question because it is a real incident many teams have had. In this answer, we will recap where these error bodies come from, go through the properties, look at how a value can change without a code change, check DevTools, and then fix and guard it.
1A Quick Recap: Where the Error Body Comes From
When an exception is not handled by our own @ExceptionHandler methods, or a resolver calls sendError, the servlet container forwards the request to /error. Spring Boot's BasicErrorController handles that path and builds the body from the ErrorAttributes bean, by default DefaultErrorAttributes. It always includes timestamp, status, error and path, and it adds four optional pieces only when properties allow: the exception message, the validation errors, the exception class name and the stack trace.
So the first question is whether the stack trace comes from this /error body at all. If the response has the trace field next to timestamp and path, it is the Boot error page. If the trace appears inside our own ProblemDetail format, our own code put it there, and the properties below are not the cause.
2The Properties That Control the Details
Four properties decide what DefaultErrorAttributes includes. include-stacktrace, include-message and include-binding-errors take the values never, always or on_param. on_param means the detail is included only when the request carries a matching parameter, trace, message or errors, set to a value other than false. include-exception is a simple true or false.
| Property | Values | Default | Adds |
|---|---|---|---|
server.error.include-stacktrace | never, always, on_param | never | trace |
server.error.include-message | never, always, on_param | never | message |
server.error.include-binding-errors | never, always, on_param | never | errors |
server.error.include-exception | true, false | false | exception (class name) |
Notice how dangerous on_param is. It looks harmless because normal clients never send the parameter, but anyone probing the API can add trace=true to any URL and get the stack trace.
3Finding Who Changed the Value
The word suddenly matters: if the code did not change, the configuration did. Spring Boot reads properties from many places, and a later source overrides an earlier one, so the value in application.properties may not be the value in effect. Common culprits are an application-dev.yml with always that got activated in production because SPRING_PROFILES_ACTIVE was changed, an environment variable SERVER_ERROR_INCLUDE_STACKTRACE=always added to a deployment manifest while debugging, and a shared file in a config server edited for one environment.
- Is trace inside Boot's /error JSON?Yescheck the error propertiesNolook at our own handlers and ErrorAttributes
- Read the effective valueActuator env, or manifests and profiles
- Value is always or on_param?Yesfind the source that sets itNocheck whether DevTools is active
- Fix the source, set never explicitly
- Add a test that asserts no trace
5 steps in order. Play them, or step through them one at a time.
The Actuator env endpoint shows each property source that defines the key and which one wins. Values are masked by default for keys that look sensitive, but this one is shown. If Actuator is not available, we compare the deployment manifests and active profiles between the last good release and now.
4Checking DevTools
Spring Boot DevTools, the development helper module, sets more verbose defaults for development, including showing the message, binding errors and stack trace on error pages. It is meant never to run in production: it disables itself when the application is started as a fully packaged jar with java -jar, and the Spring Boot build plugins leave it out of the packaged jar by default. It can still slip in if the build was changed to include it, for example a custom packaging step, or if the application is started in an unusual way that DevTools treats as development. A startup log line mentioning DevTools, or the presence of the spring-boot-devtools jar in the image, confirms it. The fix is to keep DevTools as a development-only dependency, developmentOnly in Gradle or optional in Maven.
5Fixing It and Keeping It Fixed
We remove the source that set the value, and we also set server.error.include-stacktrace=never explicitly in the production configuration, so that a stray default from somewhere else cannot change it. Then we add a test. An integration test that triggers an unhandled exception and requests the URL with trace=true asserts that the body has no trace field and no text such as at com.example, and it runs against the production profile.
It is also worth asking why the stack traces were wanted. Usually someone was debugging a production issue and needed details. The lasting answer to that need is good logs with a trace id in every error response, so details can be found in the logging system instead of in the response.
6Follow-up questions
Does on_param also apply to the message?
Yes. server.error.include-message=on_param includes the exception message when the request has message=true, and include-binding-errors=on_param includes validation errors when it has errors=true. Messages can leak as much as stack traces, so production keeps all three at never.
Our own @ControllerAdvice also returns stack traces. Do these properties help?
No. The properties only affect Spring Boot's /error output through DefaultErrorAttributes. If our handler puts ex.toString() or the stack trace into its body, we must fix the handler. The shared error advice should never include exception details in responses.
Is include-exception=true dangerous too?
Less than a stack trace, but it still reveals internal class names such as org.hibernate.exception.JDBCConnectionException, which tells an attacker what persistence stack we use. It should stay false in production.
7Conclusion
In this answer, we traced production stack traces back to Spring Boot's /error output. server.error.include-stacktrace controls the trace and defaults to never, while include-message, include-binding-errors and include-exception control the other details. A value of always or on_param, set through a profile, an environment variable or a config server, or DevTools running where it should not, explains the change. We found the source with the Actuator env endpoint, set never explicitly and added a test that requests trace=true and asserts no trace comes back.
Open with
I'd first check whether the trace is inside Spring Boot's default /error body, next to timestamp, status and path. If it is, the property in charge is server.error.include-stacktrace, whose default is never.
Then, if they want more
Its siblings are include-message and include-binding-errors, also never by default, and include-exception, which is false. The three include properties accept never, always and on_param, and on_param is sneaky: anyone can add trace=true to a URL and get the stack trace. Since it changed suddenly, I'd look for a configuration change rather than code.
I'd ask the running service for the effective value through the Actuator env endpoint, which also shows the winning property source, or compare manifests and profiles with the last good release. Typical causes are a dev profile activated in production, an environment variable like SERVER_ERROR_INCLUDE_STACKTRACE set while someone was debugging, or a config server change.
I'd also check DevTools, because it turns these details on for development; it's normally disabled for packaged jars and excluded by the build plugin, but a custom build can include it. To fix it, I'd remove the source, set never explicitly in production config, and add a test that triggers an error with trace=true and asserts there's no trace. If our own advice adds exception details, that's a separate code fix.
About this answer
- Last updated
- 12 November 2026
- 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 "In production, error responses suddenly contain stack traces. Which properties control...": https://scrivio-interview-library.netlify.app/spring-boot/error-handling/1166de401a/