Update 24.1. Adding active profiles.md

master
qibaoguang 2015-02-10 23:27:22 +08:00
parent a35185bbda
commit 0711b1e53f
1 changed files with 15 additions and 0 deletions

View File

@ -0,0 +1,15 @@
### 24.1. 添加激活的配置(profiles)
spring.profiles.active属性和其他属性一样都遵循相同的排列规则最高的PropertySource获胜。也就是说你可以在application.properties中指定生效的配置然后使用命令行开关替换它们。
有时将特定的配置属性添加到生效的配置中而不是替换它们是有用的。spring.profiles.include属性可以用来无条件的添加生效的配置。SpringApplication的入口点也提供了一个用于设置额外配置的Java API比如在那些通过spring.profiles.active属性生效的配置之上参考setAdditionalProfiles()方法。
示例:当一个应用使用下面的属性,并用`--spring.profiles.active=prod`开关运行那proddb和prodmq配置也会生效
```java
---
my.property: fromyamlfile
---
spring.profiles: prod
spring.profiles.include: proddb,prodmq
```
**注**spring.profiles属性可以定义到一个YAML文档中用于决定什么时候该文档被包含进配置中。具体参考[Section 63.6, “Change configuration depending on the environment”](http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#howto-change-configuration-depending-on-the-environment)