简体   繁体   中英

Spring boot profile not picking the properties file

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

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

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

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.

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM