|
对于最新的稳定版本,请使用 Spring Framework 6.2.10! |
@ActiveProfiles
@ActiveProfiles是一个类级注解,用于声明哪个 bean
定义配置文件在加载ApplicationContext对于
集成测试。
以下示例表示dev配置文件应处于活动状态:
-
Java
-
Kotlin
@ContextConfiguration
@ActiveProfiles("dev") (1)
class DeveloperTests {
// class body...
}
| 1 | 指示dev配置文件应处于活动状态。 |
@ContextConfiguration
@ActiveProfiles("dev") (1)
class DeveloperTests {
// class body...
}
| 1 | 指示dev配置文件应处于活动状态。 |
以下示例表示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 定义概要文件
默认情况下由超类和封闭类声明。您还可以解决活动
通过实现自定义ActiveProfilesResolver并使用resolver属性@ActiveProfiles. |
请参阅使用环境配置文件进行上下文配置,@Nested测试类配置和@ActiveProfilesjavadoc 的
示例和更多详细信息。