对于最新的稳定版本,请使用 Spring Framework 6.2.0! |
@ActiveProfiles
@ActiveProfiles
是用于声明哪个 bean 的类级 Comments
定义配置文件在加载ApplicationContext
对于
集成测试。
以下示例指示dev
profile 应处于活动状态:
-
Java
-
Kotlin
@ContextConfiguration
@ActiveProfiles("dev") (1)
class DeveloperTests {
// class body...
}
1 | 指示dev profile 应处于活动状态。 |
@ContextConfiguration
@ActiveProfiles("dev") (1)
class DeveloperTests {
// class body...
}
1 | 指示dev profile 应处于活动状态。 |
以下示例指示dev
和integration
配置文件应
保持活跃:
-
Java
-
Kotlin
@ContextConfiguration
@ActiveProfiles({"dev", "integration"}) (1)
class DeveloperIntegrationTests {
// class body...
}
1 | 指示dev 和integration 配置文件应处于活动状态。 |
@ContextConfiguration
@ActiveProfiles(["dev", "integration"]) (1)
class DeveloperIntegrationTests {
// class body...
}
1 | 指示dev 和integration 配置文件应处于活动状态。 |
@ActiveProfiles 支持继承活动的 Bean 定义配置文件
由 superclasses 声明,并默认封闭类。您还可以解析 active
bean 定义通过实现自定义ActiveProfilesResolver 并使用resolver 属性@ActiveProfiles . |
请参阅使用环境配置文件进行上下文配置。@Nested
test 类配置和@ActiveProfiles
javadoc 的
示例和更多详细信息。