Creating profiles for different environments

Up until now, we've 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 allow you 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 the 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
application.service1Url=http://abc-dev.service.com/somethingelse
application.service1Timeout=250

The values in application-dev.properties will override the default configuration in application.properties if the active profile is dev.

We can have configurations for multiple environments, as shown here:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset