Card 01/ 06
Configuration Properties: Where They Come From and Which Wins
A file, an environment variable and a command-line argument can all set the same port, in a fixed order.
A configuration property is a named setting, such as server.port, that an application reads when it starts. Spring Boot can read the same property from several sources at once, and it resolves any conflict with a fixed order of priority, so the source higher in the order always wins.
A real deployment usually sets server.port in more than one place, for different reasons: a sensible default in application.properties inside the jar, and an override for one environment, set by whoever runs the application there. On a laptop the file's server.port=8080 applies; in production the platform sets the port to 80 and that value wins, from the same jar.
From lowest to highest priority, the sources worth knowing are: application.properties on the classpath, a profile-specific file such as application-prod.properties, an operating-system environment variable, and a command-line argument. Each one can override everything before it.
An environment variable spells the property differently, in capitals with underscores: SERVER_PORT=9090 sets server.port. Boot's relaxed binding treats the two spellings as the same property, which is how a container platform can configure an application without editing any file in it.
So a command-line argument is the last word: whatever the files say, --server.port=9090 is the value the application uses. When a setting is not what you expect, check the sources from the top of the order down.
← → move through sections and cards