@ActiveProfiles
@ActiveProfiles
@ActiveProfiles 是一种注释,可以应用于测试类,用于声明在为集成测试加载 ApplicationContext 时哪些 Bean 定义的配置文件(profiles)应该是激活的。
以下示例表明 dev 配置文件应该是激活的:
- Java
- Kotlin
@ContextConfiguration
@ActiveProfiles("dev") 1
class DeveloperTests {
// class body...
}
表示
dev配置文件应该处于激活状态。
@ContextConfiguration
@ActiveProfiles("dev") 1
class DeveloperTests {
// class body...
}
表示
dev配置文件应该处于激活状态。
以下示例表明,dev和integration这两个配置文件都应该是激活状态的:
- Java
- Kotlin
@ContextConfiguration
@ActiveProfiles({"dev", "integration"}) 1
class DeveloperIntegrationTests {
// class body...
}
表示
dev和integration配置文件应该是激活的。
@ContextConfiguration
@ActiveProfiles(["dev", "integration"]) 1
class DeveloperIntegrationTests {
// class body...
}
*/
表示
dev和integration配置文件应该是激活的。
备注
@ActiveProfiles 默认支持继承由超类和包含类声明的活跃 Bean 定义配置文件。您也可以通过实现自定义的 ActiveProfilesResolver 并使用 @ActiveProfiles 的 resolver 属性进行注册,从而以编程方式解析活跃 Bean 定义配置文件。
有关示例和更多详细信息,请参阅使用环境配置文件进行上下文配置、@嵌套测试类配置,以及[Javadoc中的@ActiveProfiles。