> For the complete documentation index, see [llms.txt](https://jack80342.gitbook.io/spring-boot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jack80342.gitbook.io/spring-boot/iv.-spring-boot-features/25.-profiles/25.1.-adding-active-profiles.md).

# 25.1. 添加激活的profiles

`spring.profiles.active`属性和其他属性一样都遵循相同的排列规则：优先级最高的`PropertySource`获胜，也就是说，你可以在`application.properties`中指定生效的配置，然后使用命令行开关替换它们。

有时，将profile-specific的属性添加到激活的配置中而不是直接替换它们是有好处的。`spring.profiles.include`属性可以用来无条件的添加激活的配置，而`SpringApplication`的入口点也提供了一个用于设置其他配置的Java API，通过它设置的active配置优先级高于`spring.profiles.active`，具体参考`setAdditionalProfiles()`方法。

例如，当一个应用使用下面的属性，并用`--spring.profiles.active=prod`开关运行，那`proddb`和`prodmq` profiles也会激活：

```java
---
my.property: fromyamlfile
---
spring.profiles: prod
spring.profiles.include:
    - proddb
    - prodmq
```

**注** `spring.profiles`属性可以定义到YAML文档中，以决定何时将该文档包含进配置，具体参考[章节 74.7 根据环境改变配置](https://github.com/jack80342/spring-boot/tree/25350df33f8edd68b50ff6f6e1258c9df4f67d67/IX.%20‘How-to’%20guides/74.7%20Change%20configuration%20depending%20on%20the%20environment.md)
