|
对于最新的稳定版本,请使用 Spring Framework 6.2.7! |
@ActiveProfiles
@ActiveProfiles是用于声明哪个 bean 的类级 Comments
定义配置文件在加载ApplicationContext对于
集成测试。
以下示例指示devprofile 应处于活动状态:
-
Java
-
Kotlin
@ContextConfiguration
@ActiveProfiles("dev") (1)
class DeveloperTests {
// class body...
}
| 1 | 指示devprofile 应处于活动状态。 |
@ContextConfiguration
@ActiveProfiles("dev") (1)
class DeveloperTests {
// class body...
}
| 1 | 指示devprofile 应处于活动状态。 |
以下示例指示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. |
请参阅使用环境配置文件进行上下文配置。@Nestedtest 类配置和@ActiveProfilesjavadoc 的
示例和更多详细信息。