0
0
Spring Bootframework~10 mins

Profile-based configuration in Spring Boot - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Profile-based configuration
Start Application
Check Active Profiles
Load application.properties
Load profile-specific properties
Override common properties with profile ones
Initialize Beans with final config
Application runs with profile config
Spring Boot starts, checks which profile is active, loads common and profile-specific settings, then runs with the combined configuration.
Execution Sample
Spring Boot
spring.profiles.active=dev

# application.properties
app.name=MyApp

# application-dev.properties
app.name=MyApp-Dev
This example shows how Spring Boot loads common and dev profile properties, overriding app.name for dev.
Execution Table
StepActionProfile ActiveProperties LoadedResulting app.name
1Start applicationnoneapplication.propertiesMyApp
2Set active profile to devdevapplication.properties + application-dev.propertiesMyApp-Dev
3Initialize beans with propertiesdevfinal combined propertiesMyApp-Dev
4Application runsdevfinal combined propertiesMyApp-Dev
💡 Application runs with dev profile properties overriding common ones
Variable Tracker
VariableStartAfter Step 1After Step 2Final
spring.profiles.activenonenonedevdev
app.nameundefinedMyAppMyApp-DevMyApp-Dev
Key Moments - 2 Insights
Why does app.name change after setting the active profile?
Because after Step 2, Spring Boot loads application-dev.properties which overrides app.name from the common application.properties, as shown in the execution_table rows 2 and 3.
What happens if no profile is active?
Only application.properties is loaded, so app.name stays as MyApp, as seen in Step 1 of the execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the value of app.name after Step 1?
AMyApp-Dev
Bundefined
CMyApp
Ddev
💡 Hint
Check the 'Resulting app.name' column at Step 1 in the execution_table.
At which step does spring.profiles.active become 'dev'?
AStep 2
BStep 1
CStep 3
DStep 4
💡 Hint
Look at the 'Profile Active' column in the execution_table and variable_tracker.
If we remove application-dev.properties, what would app.name be at Step 4?
AMyApp-Dev
BMyApp
Cundefined
Ddev
💡 Hint
Without profile-specific properties, only application.properties is loaded, as shown in Step 1.
Concept Snapshot
Spring Boot loads application.properties first.
If a profile is active, it loads application-{profile}.properties next.
Profile properties override common ones.
Use spring.profiles.active to set the profile.
This allows different configs for dev, test, prod environments.
Full Transcript
When Spring Boot starts, it first checks if any profile is active using spring.profiles.active. It loads the common application.properties file. If a profile like 'dev' is active, it also loads application-dev.properties. The profile-specific properties override the common ones. For example, app.name is 'MyApp' by default but becomes 'MyApp-Dev' when the dev profile is active. Beans initialize with the combined configuration. If no profile is active, only the common properties apply. This mechanism helps run the app with different settings for different environments easily.