Profiles

Until now, we looked at how to externalize application configuration to a property file, ;application.properties. What we want to be able to do is have different values for the same property in different environments.

Profiles provide a way to provide different configurations in different environments.

The following snippet shows how to configure an active profile in application.properties:

    spring.profiles.active=dev

Once you have an active profile configured, you can define properties specific to that profile in application-{profile-name}.properties. For dev profile, the name of the properties file would be ;application-dev.properties. The following example shows the ;configuration in application-dev.properties:

 application.enableSwitchForService1=true ...

Get Mastering Spring 5.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.