繁体   English   中英

从 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 ---> 到团队 devArtem
application-prod_1.yml ---> 到团队 prod_1
application-prod_2.yml ---> 到团队 prod_2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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