此版本仍在开发中,尚未被视为稳定版本。对于最新的稳定版本,请使用 Spring Framework 6.2.0spring-doc.cadn.net.cn

@ActiveProfiles

@ActiveProfiles是一个注解,可以应用于测试类来声明哪个 Bean 定义配置文件在加载ApplicationContext对于 集成测试。spring-doc.cadn.net.cn

以下示例指示devprofile 应处于活动状态:spring-doc.cadn.net.cn

@ContextConfiguration
@ActiveProfiles("dev") (1)
class DeveloperTests {
	// class body...
}
1 指示devprofile 应处于活动状态。
@ContextConfiguration
@ActiveProfiles("dev") (1)
class DeveloperTests {
	// class body...
}
1 指示devprofile 应处于活动状态。

以下示例指示devintegration配置文件应 保持活跃:spring-doc.cadn.net.cn

@ContextConfiguration
@ActiveProfiles({"dev", "integration"}) (1)
class DeveloperIntegrationTests {
	// class body...
}
1 指示devintegration配置文件应处于活动状态。
@ContextConfiguration
@ActiveProfiles(["dev", "integration"]) (1)
class DeveloperIntegrationTests {
	// class body...
}
1 指示devintegration配置文件应处于活动状态。
@ActiveProfiles支持继承活动的 Bean 定义配置文件 由 superclasses 声明,并默认封闭类。您还可以解析 active bean 定义通过实现自定义ActiveProfilesResolver并使用resolver属性@ActiveProfiles.