# 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)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jack80342.gitbook.io/spring-boot/iv.-spring-boot-features/25.-profiles/25.1.-adding-active-profiles.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
