Card 03/ 06

ExampleDifficulty: Intermediate1 min

Switching a Whole Set of Properties at Once

A profile is a named set of properties that only takes effect when you say so. application-prod.properties sits beside application.properties and contributes nothing at all until the prod profile is active.

application.propertiestext
app.greeting=hello from application.properties
application-prod.propertiestext
app.greeting=hello from application-prod.properties
text
$ java -jar app.jar
app.greeting = hello from application.properties

$ java -jar app.jar --spring.profiles.active=prod
app.greeting = hello from application-prod.properties
run in a container — activating the profile is enough; nothing else in the code changed

One flag, --spring.profiles.active=prod, switched every property application-prod.properties sets — not just this one. That is the actual value of a profile over setting properties individually: it groups everything a given environment needs behind one name.