Configuration: profiles, properties, and secrets
One binary, many environments
A Spring Boot app should build once and deploy everywhere. Environment-specific behavior — database URLs, credentials, feature flags — lives outside the jar, in properties, environment variables, or a secret store. Profiles select the right file for each environment.
# application.properties — safe defaults for local dev
app.feature.newCheckout=false
spring.datasource.url=jdbc:h2:mem:app
# application-prod.properties — overridden in prod profile
app.feature.newCheckout=truePrecedence (highest to lowest): command-line args, OS environment variables, application-{profile}.properties, application.properties, defaults in code. Use @ConfigurationProperties to bind properties to typed, validated POJOs.
Takeaways
- One build, many environments — differences live in configuration, not code.
- Bind properties to typed objects with
@ConfigurationProperties. - Secrets never live in the jar.
Enjoying This Lesson?
Your support helps create more comprehensive courses and lessons like this one. Help me build better learning experiences for everyone.
Support Awashyak