Annotation Interface ActiveProfiles
ActiveProfiles is an annotation that can be applied to a test class
to declare which active bean definition profiles should be used when
loading an ApplicationContext
for integration tests.
This annotation may be used as a meta-annotation to create custom composed annotations.
This annotation will be inherited from an enclosing test class by default.
See @NestedTestConfiguration for details.
- Since:
- 3.1
- Author:
- Sam Brannen
- See Also:
-
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionbooleanWhether bean definition profiles from superclasses and enclosing classes should be inherited.String[]The bean definition profiles to activate.Class<? extends ActiveProfilesResolver>The type ofActiveProfilesResolverto use for resolving the active bean definition profiles programmatically.String[]Alias forprofiles().
-
Element Details
-
value
Alias forprofiles().This attribute may not be used in conjunction with
profiles(), but it may be used instead ofprofiles().- Default:
- {}
-
profiles
The bean definition profiles to activate.This attribute may not be used in conjunction with
value(), but it may be used instead ofvalue().- Default:
- {}
-
resolver
Class<? extends ActiveProfilesResolver> resolverThe type ofActiveProfilesResolverto use for resolving the active bean definition profiles programmatically.- Since:
- 4.0
- See Also:
- Default:
- org.springframework.test.context.ActiveProfilesResolver.class
-
inheritProfiles
boolean inheritProfilesWhether bean definition profiles from superclasses and enclosing classes should be inherited.The default value is
true, which means that a test class will inherit bean definition profiles defined by a test superclass or enclosing class. Specifically, the bean definition profiles for a test class will be appended to the list of bean definition profiles defined by a test superclass or enclosing class. Thus, subclasses and nested classes 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 or enclosing class.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.- See Also:
- Default:
- true
-