简体   繁体   中英

Remove other profiles from spring configuration file

I have application.yaml configuration file with few profiles:

server:
  address: 0.0.0.0
  port: 9090
db:
  url: 'jdbc:postgresql://localhost:5432/the_db'
  driver: 'org.postgresql.Driver'
  username: 'postgres'
  password: ''
---
spring:
  profiles: devArtem
db:
  url: 'jdbc:postgresql://localhost:5432/my_db'
---
spring:
  profiles: prod_1
db:
  password: 'first_pass'
---
spring:
  profiles: prod_2
db:
  password: 'second_pass'

And I want to remove other profiles before build jar file. I don't want to give access for prod_1's password to prod_2 platform for example.

For prod_1 it must be something like this:

server:
  address: 0.0.0.0
  port: 9090
db:
  url: 'jdbc:postgresql://localhost:5432/the_db'
  driver: 'org.postgresql.Driver'
  username: 'postgres'
  password: 'first_pass'

or this:

server:
  address: 0.0.0.0
  port: 9090
db:
  url: 'jdbc:postgresql://localhost:5432/the_db'
  driver: 'org.postgresql.Driver'
  username: 'postgres'
  password: ''
---
spring:
  profiles: prod_1
db:
  password: 'first_pass'

You can use multiple application-{profile}.yml and give each team the right file.

for example :

application-devArtem.yml ---> to team devArtem
application-prod_1.yml ---> to team prod_1
application-prod_2.yml ---> to team prod_2

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