Card 05/ 06
Practice: Working Out Which Property Value Wins
A base file, a production file and an active profile: which timeout does the application use?
When several sources set the same property, Spring Boot uses the one highest in its order: command line, then environment variables, then a profile-specific file, then application.properties. Apply that order to the setup below, and write down both values before you open the answer.
application.properties sets app.timeout=30. application-prod.properties sets app.timeout=10. The application is started with --spring.profiles.active=prod and no other arguments. What is the effective value of app.timeout, and why? Then answer again for the same start with the environment variable APP_TIMEOUT=20 also set.
See the answer
10. Activating the prod profile makes application-prod.properties a source with higher priority than the base application.properties. The command line sets only the profile, not app.timeout, so nothing overrides the profile file's value.
With APP_TIMEOUT=20 set as well, the value is 20: an environment variable is above every file, profile files included. Adding --app.timeout=5 to the command would make it 5, because a command-line argument is above both.
← → move through sections and cards