注释类型 ActiveProfiles
@Target(TYPE) @Retention(RUNTIME) @Documented @Inherited public @interface ActiveProfiles
ActiveProfilesis a class-level annotation that is used to declare which active bean definition profiles should be used when loading anApplicationContextfor test classes.This annotation may be used as a meta-annotation to create custom composed annotations.
- 从以下版本开始:
- 3.1
- 作者:
- Sam Brannen
- 另请参阅:
SmartContextLoader,MergedContextConfiguration,ContextConfiguration,ActiveProfilesResolver,ApplicationContext,Profile
可选元素概要
可选元素 修饰符和类型 可选元素 说明 booleaninheritProfilesWhether or not bean definition profiles from superclasses should be inherited.String[]profilesThe bean definition profiles to activate.Class<? extends ActiveProfilesResolver>resolverThe type ofActiveProfilesResolverto use for resolving the active bean definition profiles programmatically.String[]valueAlias forprofiles().
元素详细资料
value
@AliasFor("profiles") String[] value
Alias forprofiles().This attribute may not be used in conjunction with
profiles(), but it may be used instead ofprofiles().- 默认值:
- {}
resolver
Class<? extends ActiveProfilesResolver> resolver
The type ofActiveProfilesResolverto use for resolving the active bean definition profiles programmatically.- 从以下版本开始:
- 4.0
- 另请参阅:
ActiveProfilesResolver
- 默认值:
- org.springframework.test.context.ActiveProfilesResolver.class
inheritProfiles
boolean inheritProfiles
Whether or not bean definition profiles from superclasses should be inherited.The default value is
true, which means that a test class will inherit bean definition profiles defined by a test superclass. Specifically, the bean definition profiles for a test class will be appended to the list of bean definition profiles defined by a test superclass. Thus, subclasses have the option of extending the list of bean definition profiles.If
inheritProfilesis set tofalse, the bean definition profiles for the test class will shadow and effectively replace any bean definition profiles defined by a superclass.In the following example, the
ApplicationContextforBaseTestwill be loaded using only the "base" bean definition profile; beans defined in the "extended" profile will therefore not be loaded. In contrast, theApplicationContextforExtendedTestwill be loaded using the "base" and "extended" bean definition profiles.@ActiveProfiles("base") @ContextConfiguration public class BaseTest { // ... } @ActiveProfiles("extended") @ContextConfiguration public class ExtendedTest extends BaseTest { // ... }Note:
@ActiveProfilescan be used when loading anApplicationContextfrom path-based resource locations or annotated classes.- 另请参阅:
ContextConfiguration.locations(),ContextConfiguration.classes(),ContextConfiguration.inheritLocations()
- 默认值:
- true