Advanced profile management in Spring Boot

We all are aware of profile management in Spring Boot and the flexibility it provides in configuring our applications for different environments. The other powerful aspect of this is that at any given time we can have multiple active profiles. The advantage this gives is that we can mix the deployment environment profile along with business use case related profiles.

Let us assume we will have different deployments of the application in the same environment and some properties are going to change based on the deployment no matter if they are in the same environment. In such scenarios, we can have environment-specific application properties files and then each such file can override the properties which change based on different deployment.

I have defined three application properties files as shown below:,org1
  name: Test
  profiles: org1
  name: Test Org1
  profiles: org2
  name: Test Org2

Then we have a simple class AdvancedPropsDemo with the main method which prints the value of the property

public class AdvancedPropsDemo implements ApplicationRunner {

    String appName;

    public static void main(String[] args) {
        new SpringApplication(AdvancedPropsDemo.class).run(args);

    public void run(ApplicationArguments args) throws Exception {
        System.out.println("App Name value " + appName);

We have settest,org1 as active profile and Spring Boot has intelligently picked application-test.yml file and then picked the property defined in the org1 profile. In YAML property files we can create different sections for different profiles in the same file and override the required properties in their corresponding profile section

The complete code can be found here.

Leave a Reply