Sub topic 17
Inspecting and debugging effective configuration
This chapter assumes you know how property sources and precedence work, how profiles are activated, and how @ConfigurationProperties binding works. It uses the app.mail example from earlier chapters. Here you will learn how to see which values the application is actually using, and which source supplied each one.
Why "effective configuration" needs inspecting
The effective configuration is the final set of values after Spring Boot has merged every source: files, profile files, imports, environment variables, command-line arguments and test overrides. When a setting looks wrong, reading application.yaml rarely answers the question. Usually a higher-precedence source has replaced the value you wrote.
Debugging this comes down to three questions:
- Which profiles are active?
- Which source supplied the winning value?
- What did the bound object receive?
Start with the startup log
Boot logs the active profiles early in startup:
The following 1 profile is active: "prod"If no profile is active, the line reads No active profile set, falling back to 1 default profile: "default". Check this line first. A missing or misspelled profile name explains many "my prod file is ignored" problems. A profile-specific file for a profile that is not active is skipped silently.
To see how Boot locates and loads config files, raise the log level of the config data loader:
logging.level.org.springframework.boot.context.config=traceThe trace output lists each location Boot checks and whether it was found. It also shows optional imports that were skipped. This helps with spring.config.import problems and files placed in the wrong directory.
Ask the Environment directly
The Environment holds an ordered list of property sources, and the first source that contains a key wins. You can walk that list yourself. The following runner prints every source that defines app.mail.port, in precedence order:
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertySource;
import org.springframework.stereotype.Component;
@Component
class ConfigReport implements CommandLineRunner {
private final ConfigurableEnvironment environment;
ConfigReport(ConfigurableEnvironment environment) {
this.environment = environment;
}
@Override
public void run(String... args) {
String key = "app.mail.port";
System.out.println("Active profiles: " + String.join(",", environment.getActiveProfiles()));
for (PropertySource<?> source : environment.getPropertySources()) {
if (source.containsProperty(key)) {
System.out.println(source.getName() + " -> " + source.getProperty(key));
}
}
}
}The first line printed is usually a source named configurationProperties. This is an adapter that Boot places at the front so relaxed binding works. It reports the same winning value as the real source below it, so look at the second entry to find the true origin.
Use Actuator endpoints
For a running application, Spring Boot Actuator exposes the same information over HTTP. Add the starter:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>Only the health endpoint is exposed over HTTP by default, so enable the endpoints you want. The configuration below does that only when a local profile is active:
spring:
config:
activate:
on-profile: local
management:
endpoints:
web:
exposure:
include: env,configprops,conditions
endpoint:
env:
show-values: always
configprops:
show-values: alwaysThis file belongs in application-local.yaml, or in a later YAML document of application.yaml as shown. Either way it applies only when local is active. Do not expose these endpoints in production without authentication.
The three endpoints answer different questions:
| Endpoint | Path | Answers |
|---|---|---|
| env | `/actuator/env` | Which property sources exist, and what each contains |
| env (single key) | `/actuator/env/app.mail.port` | Which source supplied this key, and which sources were overridden |
| configprops | `/actuator/configprops` | What values each `@ConfigurationProperties` bean was bound to |
| conditions | `/actuator/conditions` | Which auto-configurations matched and why |
Tracing one property
Call /actuator/env/app.mail.port while the app runs with --app.mail.port=2525 and the prod profile. The response looks like this, shortened:
{
"property": { "source": "commandLineArgs", "value": "2525" },
"activeProfiles": ["prod"],
"propertySources": [
{ "name": "commandLineArgs", "property": { "value": "2525" } },
{
"name": "Config resource 'class path resource [application.yaml]' via location 'optional:classpath:/' (document #1)",
"property": {
"value": "587",
"origin": "class path resource [application.yaml] - 9:11"
}
},
{
"name": "Config resource 'class path resource [application.yaml]' via location 'optional:classpath:/' (document #0)",
"property": { "value": "1025" }
}
]
}The top-level property object shows the winner. The propertySources list shows every definition, in precedence order. In this example, the command-line value wins over the prod document (587), which wins over the default document (1025). The origin field gives the file, line and column.
Checking the bound object
/actuator/configprops shows what binding produced, which can differ from the raw strings. It is the right tool when a property is "set" but the Java object has the wrong value. For example, an environment variable APP_MAIL_RETRYATTEMPTS does not bind to retry-attempts the way APP_MAIL_RETRY_ATTEMPTS... Check the exact mapping rules: Boot converts retry-attempts to APP_MAIL_RETRYATTEMPTS by removing dashes. So APP_MAIL_RETRYATTEMPTS is correct, and APP_MAIL_RETRY_ATTEMPTS would be a different key that never binds. The configprops output shows the default of 3 still in place when that happens.
Values are masked by default
Since Spring Boot 3.0, /actuator/env and /actuator/configprops hide all values by default (show-values is never). You can set show-values to when-authorized so that only users with the right role see them. Before 3.0, Boot masked only keys that matched names like password, secret or key. The default is now safer, and it is also why the example above sets always for the local profile only.
Find out why a bean or auto-configuration is missing
Profile-dependent beans can fail in two ways: no bean matches, or several do. Both appear as startup errors from the failure analyzer. For NotifierConfig from the profiles chapter, a missing bean would read No qualifying bean of type 'Notifier'. That usually means no profile condition matched. Check the active profiles line first.
For auto-configuration, start with --debug:
java -jar app.jar --debugThis prints the condition evaluation report, with "Positive matches", "Negative matches" and "Unconditional classes". It is useful when a property such as spring.datasource.url seems ignored because the auto-configuration that reads it never applied. --debug turns on debug logging for core Boot loggers only. It does not change your own application's log levels.
A debugging workflow
Common causes found this way
- A leftover environment variable such as
APP_MAIL_PORTon the machine or in the container overrides the file. Theenvendpoint showssystemEnvironmentas the winner. - A
local-overrides.yamlimported withoptional:is present on one machine only. The origin points to it. - A test sets a property inline, so it differs from the running application. The
@SpringBootTest(properties = ...)source ranks above files. - A profile name differs in case or spelling, such as
Prodandprod. The startup line shows what Boot actually activated. - A key is misspelled in YAML. Nothing fails, because unknown keys are ignored by default.
configpropsshows the default value instead.
Exercises
Exercise
A teammate says the prod host in application.yaml is ignored. /actuator/env/app.mail.host shows systemEnvironment as the winning source with the value smtp.internal.example. What happened, and what is the fix?
Show answer
The environment variable APP_MAIL_HOST is set on the machine or container. Environment variables rank above packaged config files, so the file value is overridden. Remove or correct the variable. The propertySources list in the same response still shows the file value, which confirms it was overridden and not missing.
Exercise
Your /actuator/env response lists every value as ******. Which setting controls this, and how would you make values visible only to authorized users?
Show answer
The management.endpoint.env.show-values property controls it, and since Spring Boot 3.0 its default is never. Set it to when-authorized, and set management.endpoint.env.roles if you need specific roles. Use always only in local profiles. The same pattern applies to management.endpoint.configprops.show-values.