Home > Net >  The Spring profile property values being overridden in yaml file
The Spring profile property values being overridden in yaml file

Time:03-29

So my property file looks like:-

spring:
 profiles:
   active: {SPRING_PROFILE:default}
---
spring:
 application:
   name: application-mode1
 config:
   activate:
     on-profile: mode1
config:
 filter:
  ruleId: 1
---
spring:
 application:
   name: application-mode2
 config:
   activate:
     on-profile: mode2
config:
 filter:
  ruleId: 2

I am setting the SPRING_PROFILE value at runtime. So there is two deployment of same application in same environment. The two profiles(mode1, mode2) are getting mapped to specific deployments as the spring starter log "message":"The following profiles are active: mode1", suggested but when it comes to fetching the ruleId only the last mentioned and updated value is getting fetched by both the apps not the profile specific rule id. In this case it is 2 but if I reverse this it will be 1 for both the apps. kindly suggest any alternative. This app is deployed using kubernetes.

CodePudding user response:

The configuration you're using works only from Spring boot 2.4 and higher (see relevant blogpost).

Before that, you had to use the spring.profiles property. For example:

spring:
 profiles:
   active: ${SPRING_PROFILE:default} # The dollar sign was also missing
---
spring:
 application:
   name: application-mode1
 profiles: mode1
config:
 filter:
  ruleId: 1
---
spring:
 application:
   name: application-mode2
 profiles: mode2
config:
 filter:
  ruleId: 2
  • Related