我的应用配置文件application.yml
中有多个配置文件,如下例所示:
spring:
application:
name: my-super-app
database:
secret: "default secret"
this:
that: "default value..."
---
spring:
profiles: staging
---
spring:
profiles: qa
database:
secret: "foo bar"
---
spring:
profiles: playground
database:
secret: "foo bar"
---
spring:
profiles: production
database:
secret: "foo bar"
很明显,我为database.secret
,qa
和playground
配置文件冗余设置production
配置,staging
除外。有没有办法为这三个配置文件设置一次,对配置文件进行分组或从基本配置文件继承?
答案 0 :(得分:0)
您可以将逗号分隔列表(qa,playground,production
)组合在一起,如下所示:
spring:
application:
name: my-super-app
common-secret: "foo bar"
database:
secret: "default secret"
this:
that: "default value..."
---
spring:
profiles: staging
---
spring:
profiles: qa
---
spring:
profiles: playground
---
spring:
profiles: production
---
spring:
profiles: qa,playground,production
database:
secret: "foo bar"
或者你可以设置一个“共享变量”,如下所示:
spring:
application:
name: my-super-app
common-secret: "foo bar"
database:
secret: "default secret"
this:
that: "default value..."
---
spring:
profiles: staging
---
spring:
profiles: qa
database:
secret: ${common-secret}
---
spring:
profiles: playground
database:
secret: ${common-secret}
---
spring:
profiles: production
database:
secret: ${common-secret}