10 · Spring and Spring Boot / LESSON 47 OF 102
Configuration and profiles
Use the same artifact across environments.
Before this lesson: Beans, injection, and layers
Understand the topic
application.properties provides defaults; profiles select environment-specific configuration. Environment variables override settings. Never commit database passwords or production secrets.
Use @ConfigurationProperties for groups of related settings. Activate profiles explicitly with --spring.profiles.active=dev. Actuator is useful for health, but only expose the management endpoints you need.
EXAMPLE · PROPERTIES
src/main/resources/application.properties
spring.application.name=tasks-api
server.port=8080
management.endpoints.web.exposure.include=health,info
management.endpoint.health.show-details=never
# Later, set datasource configuration through environment variables.
# SPRING_DATASOURCE_URL=jdbc:postgresql://localhost:5432/tasksWhat to expect
GET /actuator/health returns health status when Actuator is installed.
YOUR TURN
Put it into practice
- 01Override SERVER_PORT to 8081.
- 02Create and activate a dev profile.
- 03Keep secret values out of Git.
Pass a quiz or complete a lab to check today’s streak. Each lesson counts once per day, including when you review it later.
UNDER THE HOOD
Build the mental model
Separate deploy-time choices from application behavior, and validate required configuration early.
- 01Defaults belong in version control only when safe for all environments. Secrets belong in the deployment environment or a secret manager.
- 02Profiles group related choices but do not provide security by themselves. Confirm the active profile in startup logs.
- 03Bind related properties into a typed configuration object and reject invalid values at startup instead of failing on the first request.
A mistake worth avoiding
A profile named production does not make an unsafe default safe.
DEBUGGING ROOM
Something broke. Where do you look?
The service connects to the development database in deployment.
Before revealing the diagnosis, write down your first investigation step.
CHECK YOUR UNDERSTANDING
Which belongs in the repository?
BUILD IT YOURSELF
Create development and test configuration
- 1.Define separate local database names for dev and test.
- 2.Validate a required custom setting.
- 3.Document all environment variables without values.
Acceptance checklist
Lab completion is your self-report. Knowledge checks do not certify project quality.
RETRIEVE IT FROM MEMORY
How do you prove which configuration actually won?
Revisit this lesson in three days after a successful check or lab.
Ready for the next step?
Explain configuration precedence and profiles.
Reading is separate from passing a knowledge check or completing a lab.