Configuration — Properties, Profiles and Overrides
library-service lends books for 14 days on your laptop, but the head librarian wants 21 days in production, and the database password must never sit in the code. Spring Boot's configuration system lets the same jar behave differently in each place without being rebuilt.
The rule
Defaults live in the file; the environment overrides; the closest source wins.
Settings live in src/main/resources/application.properties (or the YAML form, application.yml):
server.port=8080
spring.application.name=library-service
library.loan.max-days=14
library.loan.max-books=5Keys starting with server. or spring. are read by Boot itself. Keys like library.loan.* are your own, and you bind them to a typed class:
@ConfigurationProperties(prefix = "library.loan")
public record LoanProperties(int maxDays, int maxBooks) {}Register it with @ConfigurationPropertiesScan (or @EnableConfigurationProperties(LoanProperties.class)) and inject LoanProperties wherever it is needed. Note the relaxed binding: max-days in the file becomes maxDays in Java. For a single value you can also write @Value("${library.loan.max-days}"), but a typed class keeps related settings together.
Profiles group settings for one environment. A file named application-prod.properties is loaded only when the prod profile is active, and its values override the plain file:
# application-prod.properties
library.loan.max-days=21Activate it with spring.profiles.active=prod, for example as an environment variable SPRING_PROFILES_ACTIVE=prod.