Spring Boot resolves properties by checking sources in a specific order. Command line arguments have the highest priority, allowing quick overrides without changing files.
server.port when the application starts?- application.properties file:
server.port=8080- Environment variable:
SERVER_PORT=9090- Command line argument:
--server.port=7070Command line arguments override environment variables and property files, so 7070 is used.
application.properties file to be ignored, making environment variables take precedence?If spring.config.location points to a missing directory, Spring Boot skips loading application.properties from default locations, so environment variables take precedence.
-
application.properties: app.mode=dev-
application-dev.properties: app.mode=development- Environment variable:
APP_MODE=production- Command line argument:
--app.mode=stagingIf the app is started with the profile
dev, what is the final value of app.mode?Command line arguments have the highest priority, so staging is the final value regardless of profile.
spring.config.additional-location to a directory containing application.properties with feature.enabled=false. The default application.properties in src/main/resources has feature.enabled=true. The app always uses false for feature.enabled. Why?Choose the correct explanation.
Properties in spring.config.additional-location override those in default locations, so feature.enabled=false takes precedence.
