Spring Boot NotesBeginner
Configuration & application.yml
application.yml vs properties, externalizing secrets, and type-safe config binding.
Configuration & application.yml
application.properties vs application.yml
Both configure the app; YAML is more readable for nested config (and is the more common modern choice).
# application.yml
server:
port: 8080
spring:
datasource:
url: jdbc:postgresql://localhost:5432/fintrack
username: ${DB_USER}
password: ${DB_PASSWORD}
jpa:
hibernate:
ddl-auto: validate
show-sql: true
app:
jwt:
secret: ${JWT_SECRET}
expiration-ms: 3600000# equivalent application.properties
server.port=8080
spring.datasource.url=jdbc:postgresql://localhost:5432/fintrackExternalizing Secrets with Environment Variables
Never hardcode secrets. Use ${ENV_VAR} placeholders and supply them via:
.envfile + Docker Composeenv_file- CI/CD secret store (GitHub Actions secrets)
- Cloud provider secret manager (Oracle Cloud Vault, AWS Secrets Manager)
Type-Safe Configuration with @ConfigurationProperties
Instead of scattering @Value("${app.jwt.secret}") everywhere, bind a whole
config block to a class:
@Configuration
@ConfigurationProperties(prefix = "app.jwt")
public class JwtProperties {
private String secret;
private long expirationMs;
// getters/setters
}Then inject JwtProperties wherever needed — it's testable, IDE-autocompletes,
and validates types at startup.
@Value for One-Off Values
@Value("${server.port}")
private int port;Fine for a single simple value; prefer @ConfigurationProperties for related
groups of values.
Profile-Specific Configuration (preview)
application.yml # common config
application-dev.yml # dev overrides
application-prod.yml # prod overridesActivate with spring.profiles.active=dev (env var, JVM arg, or in the base
YAML). Full details in the Profiles topic later.
Configuration Precedence (high to low, common ones)
- Command-line arguments (
--server.port=9090) SPRING_APPLICATION_JSONenv var- OS environment variables
application-{profile}.ymlapplication.yml@PropertySourceannotated values- Default values in code
Last updated on July 15, 2026