Home > Software design >  Spring boot profile not picking the properties file
Spring boot profile not picking the properties file

Time:09-01

I have application-database.yml, application-sql.yml.Tried running using -Dspring.profiles.active=local but properties data not picking up. How to run this?

application-local.yml

spring:
  profiles:
    group:
      local: database, sql, message
  application: 
    name: HP-FETCHER-CONFIG-SERVICE

CodePudding user response:

by Dspring.profiles.active=local you are telling spring that you use local profile, use Dspring.profiles.active=database instead

CodePudding user response:

I'm not sure if this applies to your project:

just use application.yml,then:

spring:                                                                                                                                                                                                
  profiles:                                                                     
    active: local, database, sql

---                                                                                                                
spring:                                                                                                            
  profiles: local1
  ...
...

---                                                                                                                
spring:                                                                                                            
  profiles: local
  ...
...

---                                                                                                                
spring:                                                                                                            
  profiles: sql
  ...
...

---                                                                                                                
spring:                                                                                                            
  profiles: database
  ...
...

when start without -Dspring.profiles.active it will use the local, database, sql. if start with -Dspring.profiles.active=local1,database,sql it will use the local1, database, sql

CodePudding user response:

If you want to use group you have to specify it in either application.yml or application.properties file. The corresponding blog post says:

To define a group, you can use the spring.profiles.group property in your application.properties or application.yml file.

CodePudding user response:

For me this seems to be working as expected. I have the below application.yml file

spring:
  profiles:
    group:
      super-1-2: profile-1, profile-2
      super-2-3: profile-2, profile-3

---
spring:
  config:
    activate:
      on-profile:
      - profile-1
      
---
spring:
  config:
    activate:
      on-profile:
      - profile-2

---
spring:
  config:
    activate:
      on-profile:
      - profile-3

If I run my application with profile super-1-2 activated, I get a confirmation in my logs that all three super-1-2, profile-1 and profile-2 are active.

2022-08-31 16:52:27.109  INFO 67935 --- [  restartedMain] c.s.n.SampleApplication      : The following 3 profiles are active: "super-1-2", "profile-1", "profile-2"

On the other hand, if I run my application with profile super-2-3 activated, I get a confirmation in my logs that all three super-2-3, profile-2, and profile-3 are active.

2022-08-31 16:52:41.117  INFO 68090 --- [  restartedMain] c.s.n.SampleApplication      : The following 3 profiles are active: "super-2-3", "profile-2", "profile-3"
  • Related