Externalised configuration: Spring Boot reads properties from many sources and merges them by precedence, so the same JAR runs in every environment.
Common sources, roughly from lowest to highest priority:
- application.yml / application.properties inside the JAR.
- Profile-specific files such as application-prod.yml.
- Files outside the JAR (for example, mounted config in Kubernetes).
- Environment variables, such as SPRING_DATASOURCE_URL.
- Command-line arguments, such as --server.port=9090.
Profiles:
- Activate with spring.profiles.active=prod (property, environment variable or argument).
- Profile files override the defaults; @Profile("dev") limits beans to a profile, for example a fake email sender in dev.
- Profile groups (spring.profiles.group.prod=db-prod,mq-prod) combine several.
Type-safe binding:
- Prefer @ConfigurationProperties(prefix = "app.payment") on a record or class with validation (@Validated) over many @Value annotations.
Secrets: never commit them. Inject them through environment variables or a secret manager (Vault, AWS Secrets Manager, Kubernetes secrets).