此版本仍在开发中,尚不被认为是稳定的。对于最新的稳定版本,请使用 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
测试类配置和@ActiveProfiles
javadoc 的
示例和更多详细信息。