从 spring 配置文件中删除其他配置文件

Remove other profiles from spring configuration file

我有 application.yaml 配置文件,配置文件很少:

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'

而且我想在构建 jar 文件之前删除其他配置文件。例如,我不想让 prod_1 的密码访问 prod_2 平台。

对于prod_1,它必须是这样的:

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'

或者这个:

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'

您可以使用多个 application-{profile}.yml 并为每个团队提供正确的文件。

例如:

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