Sub topic 17
Inspecting and debugging effective configuration
This chapter assumes you know property sources and precedence, @ConfigurationProperties, and profiles from the earlier chapters. It covers how to see which values your running application is using and where each one came from.
Start with the startup log
Spring Boot logs the active profiles when it starts. Look for a line like this:
The following 1 profile is active: "prod"If it says No active profile set, falling back to 1 default profile: "default", your activation setting never reached the application. Typical causes are a misspelled environment variable or an argument placed before -jar.
Ask Actuator which source won
Add the Actuator starter, spring-boot-starter-actuator. Then expose the two endpoints that report configuration:
management:
endpoints:
web:
exposure:
include: env,configprops
endpoint:
env:
show-values: WHEN_AUTHORIZED
configprops:
show-values: WHEN_AUTHORIZEDSince Spring Boot 3, these endpoints mask all values unless you opt in. WHEN_AUTHORIZED shows them only to authorized users, and ALWAYS shows them to everyone. Use ALWAYS only on a local machine.
| Endpoint | Answers the question |
|---|---|
| `/actuator/env` | Which property sources exist, in precedence order, and what is in each? |
| `/actuator/env/app.mail.port` | Which source supplied this one key, and which sources it overrode? |
| `/actuator/configprops` | What did each `@ConfigurationProperties` bean actually bind? |
The single-key form is the most useful for debugging. Its response names the winning source, such as commandLineArgs or systemEnvironment. It also lists every other source that defines the key, in precedence order.
Log the values yourself
When Actuator is not an option, print the effective values at startup. Never log secrets.
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
@Component
class ConfigReport implements ApplicationRunner {
private static final Logger log = LoggerFactory.getLogger(ConfigReport.class);
private final Environment env;
private final MailProperties mail;
ConfigReport(Environment env, MailProperties mail) {
this.env = env;
this.mail = mail;
}
@Override
public void run(ApplicationArguments args) {
log.info("Active profiles: {}", Arrays.toString(env.getActiveProfiles()));
log.info("app.mail.host={} port={}", mail.host(), mail.port());
}
}See how files are loaded
To find out why a file was or was not read, raise the log level of the config data loader:
java -jar app.jar --logging.level.org.springframework.boot.context.config=TRACEThe trace shows each location Spring Boot checked, each file it found, and each profile-specific document it skipped. Starting with --debug also prints the auto-configuration conditions report, which helps when a @Profile or conditional bean is missing.
Common causes of surprises
- A higher source hides your file. An environment variable such as
APP_MAIL_PORTbeatsapplication.yaml. - The profile document was skipped. A multi-document
on-profileblock applies only when that profile is active. - The key does not match. In
configprops, a property that stayed at its default often points to a misspelled key.
Exercise
/actuator/env/app.mail.port reports commandLineArgs as the winning source, but you expected the prod section of application.yaml. What does that tell you, and what do you check next?
Show answer
Someone passed --app.mail.port=... to the process, and command-line arguments rank above packaged YAML files. Check the launch command, such as a service file or container entrypoint, and remove the argument or change its value. The same response lists the YAML value as an overridden source, which confirms the file is being read.