Video in progress
If a setting is defined in several places, which value does Spring Boot use?
There's an order: command-line arguments > env variables > profile file (application-prod.yml) > the common application.yml > @PropertySource > defaults. The one on the left overrides the one on the right.
📖 Answer
Simplified order (strongest to weakest):
--server.port=9000— command line;SPRING_APPLICATION_JSON;- Java system property:
-Dserver.port=9000; - OS env variable:
SERVER_PORT=9000; application-{profile}.ymloutside the jar, thenapplication.yml;application-{profile}.ymlinside the jar, thenapplication.yml;@PropertySource,SpringApplication.setDefaultProperties.
In practice it works like this: defaults live inside the jar, and on the server you override them with env variables — no rebuild needed.
Env names are matched through "relaxed binding": spring.datasource.url → SPRING_DATASOURCE_URL (dots become _, letters uppercase).
If you can't figure out where a value came from, /actuator/env (internal network only!) shows the source of every key.
Sign up to mark studied questions and save your progress.