@ActiveProfiles
@ActiveProfiles 是一个类级注解,用于声明在为集成测试加载 ApplicationContext 时哪些 bean 定义配置文件 (profiles) 应该是活动的。
以下示例指示 dev 配置文件应该是活动的:
-
Java
@ContextConfiguration
@ActiveProfiles("dev") (1)
class DeveloperTests {
// 类体...
}
| 1 | 指示 dev 配置文件应该是活动的。 |
以下示例指示 dev 和 integration 配置文件都应该是活动的:
-
Java
@ContextConfiguration
@ActiveProfiles({"dev", "integration"}) (1)
class DeveloperIntegrationTests {
// 类体...
}
| 1 | 指示 dev 和 integration 配置文件都应该是活动的。 |
@ActiveProfiles 默认支持继承由超类和封闭类声明的活动 bean 定义配置文件。
您还可以通过实现自定义 ActiveProfilesResolver 并使用 @ActiveProfiles 的 resolver 属性注册它来以编程方式解析活动 bean 定义配置文件。
|
有关示例和更多详细信息,请参阅 使用环境配置文件的上下文配置、@Nested 测试类配置 和 @ActiveProfiles javadoc。