Annotation Type ActiveProfiles
@Target(TYPE) @Retention(RUNTIME) @Documented @Inherited public @interface ActiveProfiles
ActiveProfiles
is a class-level annotation that is used to declare which active bean definition profiles should be used when loading anApplicationContext
for test classes.This annotation may be used as a meta-annotation to create custom composed annotations.
- Since:
- 3.1
- Author:
- Sam Brannen
- See Also:
SmartContextLoader
,MergedContextConfiguration
,ContextConfiguration
,ActiveProfilesResolver
,ApplicationContext
,Profile
Optional Element Summary
Optional Elements Modifier and Type Optional Element Description boolean
inheritProfiles
Whether or not bean definition profiles from superclasses should be inherited.String[]
profiles
The bean definition profiles to activate.Class<? extends ActiveProfilesResolver>
resolver
The type ofActiveProfilesResolver
to use for resolving the active bean definition profiles programmatically.String[]
value
Alias forprofiles()
.
Element Detail
value
@AliasFor("profiles") String[] value
Alias forprofiles()
.This attribute may not be used in conjunction with
profiles()
, but it may be used instead ofprofiles()
.- Default:
- {}
resolver
Class<? extends ActiveProfilesResolver> resolver
The type ofActiveProfilesResolver
to use for resolving the active bean definition profiles programmatically.- Since:
- 4.0
- See Also:
ActiveProfilesResolver
- Default:
- 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
inheritProfiles
is 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
ApplicationContext
forBaseTest
will be loaded using only the "base" bean definition profile; beans defined in the "extended" profile will therefore not be loaded. In contrast, theApplicationContext
forExtendedTest
will 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:
@ActiveProfiles
can be used when loading anApplicationContext
from path-based resource locations or annotated classes.- See Also:
ContextConfiguration.locations()
,ContextConfiguration.classes()
,ContextConfiguration.inheritLocations()
- Default:
- true