我有 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_2 平台授予 prod_1 密码的访问权限。
对于 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
关于java - 从 spring 配置文件中删除其他配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39899468/