Spring Property Profile

We can set a profile using spring.profiles.active

[!note]
The spring.profiles.active only can be set in a non-profile specific
file (i.e not one of the application-{profile}.yml file)

The spring.profiles.active can only be set in the application.yml or application.properties file.

We can set the active spring profile as following:

spring:  
  profiles:  
    active: "sit"  

As a result, it will load application-sit.yml or application.yml with multi-document in application.yml of spring.config.activate.on-profile: sit

To have multiple profiles active on the same time, we can do

spring:  
  profiles:  
    active: "sit, sit1"  

As a result, it will read application-sit.yml and pick up sit1 of Spring Property File > Multi-document:

environment: sit  
  
---  
  
spring:  
  config:  
    activate:  
      on-profile: 'sit1'  
  application:  
    name: "Springboot sit application (${environment}1)"  
  
---  
  
spring:  
  config:  
    activate:  
      on-profile: 'sit2'  
  application:  
    name: "Springboot sit application (${environment}2)"

Overwrite the active profile

If we want to overwrite the active profile, we can use spring.profiles.include: some-environment. As a result, the include will overwrite and add on if there is any missing in the active profile.

Profile group

A profile group is a group that include multiple profile. For example we can do something like this:

spring:  
  profiles:  
    active: shake-out-testing  
    group:  
      shake-out-testing:  
        - sit  
        - sit2