Configuration Management

You will learn about configuration management using spring boot.

In this lesson, we will learn about configuration management and maintaining profiles.

Basics of configuration management

Spring Boot, by default, reads the configurations from application.properties located at src/main/resources. The configuration file can be represented as application.yml.

Maintaining profiles

Spring Boot allows us to maintain configuration files of different profiles in the format application-<profile>.properties, and these properties’ files need to be present in src/main/resources.

Example: application-dev.properties or application-staging.properties or application-prod.properties.

To activate a profile, we can set the property spring.profiles.active = dev in application.properties, where dev can be replaced with the desired profile name, as shown below:

src/main/resources/application.properties

spring.profiles.active = dev

The property that is accessed will be looked up in the current activate profile. If not found, it falls back to the one present in the default application.properties. If neither property is found and the configuration parameter is marked mandatory, Spring will throw an exception saying the expected property is missing.

We can also annotate beans to be created only when the active profile is set to a certain profile, as shown in the following snippet:

Get hands-on with 1400+ tech skills courses.