[英]setting spring configuration for multiple profile
I have more than one profile in my application configuration file, application.yml
, like the following example: 我的应用程序配置文件
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"
As it is obvious, I redundantly set the database.secret
configuration for qa
, playground
and production
profiles, except staging
. 显而易见,我除了为
staging
之外,为qa
, playground
和production
配置文件冗余设置了database.secret
配置。 Is there a way to set it once for these three profiles, something grouping the profiles or inheriting from a base profile? 有没有一种方法可以为这三个配置文件设置一次,对配置文件进行分组或从基本配置文件继承?
You can combine the profiles in a comma separated list ( qa,playground,production
), like this: 您可以将配置文件合并到以逗号分隔的列表(
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"
Alternately you can set a "shared variable", something like this: 或者,您可以设置“共享变量”,如下所示:
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}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.