Video in progress
If the same property is set in application.yml, in an env var and in a command-line argument, which one does Spring Boot take?
The command-line argument wins, then the env var, and last the application.yml inside the jar. The general rule: a source supplied from outside and "closer" to the running process overrides the one inside.
📖 Answer
# in application.yml: server.port: 8080
export SERVER_PORT=9090
java -jar app.jar --server.port=7070
# Tomcat started on port 7070
A simplified order (the higher one wins):
--server.port=...command-line arguments;SPRING_APPLICATION_JSON;- Java system properties (
-Dserver.port=...); - OS environment variables;
application-{profile}.ymloutside the jar;application.ymloutside the jar;application-{profile}.ymlinside the jar;application.ymlinside the jar.
Note: since Boot 2.4, a plain application.yml outside the jar beats even the profile file inside the jar. Older articles list the order differently.
This order is why one image works in every environment: the defaults are inside the jar, and the environment-specific values are in the Kubernetes env.
A situation that confuses people when debugging: "I changed the yml and nothing happened." The cause is often a forgotten env var in the deployment manifest or in a ConfigMap. /actuator/env (only if it is exposed on the internal network alone) shows exactly which source a value came from.
Sign up to mark studied questions and save your progress.