> 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.md).

# 25. Profiles

Spring Profiles提供了一种隔离应用程序配置的方式，并让这些配置只在特定的环境下生效。任何`@Component`或`@Configuration`都能注解`@Profile`，从而限制加载它的时机：

```java
@Configuration
@Profile("production")
public class ProductionConfiguration {

    // ...

}
```

你可以使用`spring.profiles.active`的`Environment`属性来指定哪个配置生效。你可以使用在这一章的前面描述过的任何方式来指定该属性。例如，可以将它包含到`application.properties`中：

```java
spring.profiles.active=dev,hsqldb
```

或使用命令行开关：

```
--spring.profiles.active=dev,hsqldb
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://jack80342.gitbook.io/spring-boot/iv.-spring-boot-features/25.-profiles.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
