Spring Boot resolves configuration properties from multiple sources using a defined order of precedence, so the same property can be safely overridden differently across environments.
Key Points: • Command-line arguments (--server.port=9090) have the highest precedence. • JVM system properties and OS environment variables are next, useful for container/orchestration-level overrides. • Profile-specific configuration files (application-prod.yml) override the base application.yml/properties. • The base application.properties/application.yml file provides the general defaults for the application. • Spring Boot's own built-in defaults apply last, when nothing else specifies a value. • Higher-precedence sources are typically used for environment-specific or deployment-time overrides, while the base file holds sensible general defaults.
Example: If application.yml sets server.port: 8080 but the container starts the app with java -jar app.jar --server.port=9090, the application runs on port 9090, because command-line arguments take priority over file-based configuration.
Interview Tip: A concise interview answer is:
"Command-line arguments win first, then environment variables and system properties, then profile-specific files like application-prod.yml, then the base application.yml, and finally Spring Boot's own defaults. That hierarchy is exactly what lets the same build run correctly in different environments just by overriding values at the right level."