Card 03/ 06
Profiles Example: Switching a Whole Set of Properties at Once
One flag switches every setting a production file defines, not just one of them.
A profile is a named set of properties that only takes effect when you activate it. application-prod.properties sits beside application.properties and contributes nothing at all until the prod profile is active.
The base file and the production file each set the same property:
app.greeting=hello from application.propertiesapp.greeting=hello from application-prod.propertiesRunning the same jar without a profile, and then with --spring.profiles.active=prod:
java -jar app.jar
app.greeting = hello from application.properties
java -jar app.jar --spring.profiles.active=prod
app.greeting = hello from application-prod.propertiesOne flag switched every property application-prod.properties sets, not only this one. In a real application the production file would hold the database address, the logging level and the cache sizes, and all of them change together.
So a profile groups everything one environment needs behind one name. The profile can also be activated with the environment variable SPRING_PROFILES_ACTIVE=prod, which is how most deployment platforms set it. Several profiles can be active at once, separated by commas, and where two profile files disagree the profile listed last wins.
← → move through sections and cards