org.springframework.test.context
Annotation Type ContextConfiguration


@Documented
@Inherited
@Retention(value=RUNTIME)
@Target(value=TYPE)
public @interface ContextConfiguration

ContextConfiguration defines class-level metadata which can be used to instruct client code with regard to how to load and configure an ApplicationContext.

Since:
2.5
Author:
Sam Brannen
See Also:
ContextLoader, ApplicationContext

Optional Element Summary
 boolean inheritLocations
          Whether or not resource locations from superclasses should be inherited.
 Class<? extends ContextLoader> loader
          The type of ContextLoader to use for loading an ApplicationContext.
 String[] locations
          The resource locations to use for loading an ApplicationContext.
 String[] value
          Alias for locations.
 

value

public abstract String[] value
Alias for locations.

Since:
3.0
Default:
{}

locations

public abstract String[] locations
The resource locations to use for loading an ApplicationContext.

Check out org.springframework.test.context.support.AbstractContextLoader#modifyLocations)'s javadoc for details on how a location String will be interpreted at runtime, in particular in case of a relative path. Also, check out the documentation on AbstractContextLoader.generateDefaultLocations(java.lang.Class) for details on the default locations that are going to be used if none are specified.

Note that the above-mentioned default rules only apply for a standard AbstractContextLoader subclass such as GenericXmlContextLoader which is the effective default implementation used at runtime.

Default:
{}

inheritLocations

public abstract boolean inheritLocations
Whether or not resource locations from superclasses should be inherited.

The default value is true, which means that an annotated class will inherit the resource locations defined by an annotated superclass. Specifically, the resource locations for an annotated class will be appended to the list of resource locations defined by an annotated superclass. Thus, subclasses have the option of extending the list of resource locations. In the following example, the ApplicationContext for ExtendedTest will be loaded from "base-context.xml" and "extended-context.xml", in that order. Beans defined in "extended-context.xml" may therefore override those defined in "base-context.xml".

 @ContextConfiguration("base-context.xml")
 public class BaseTest {
        // ...
 }
 
 @ContextConfiguration("extended-context.xml")
 public class ExtendedTest extends BaseTest {
        // ...
 }
 
If inheritLocations is set to false, the resource locations for the annotated class will shadow and effectively replace any resource locations defined by a superclass.

Default:
true

loader

public abstract Class<? extends ContextLoader> loader
The type of ContextLoader to use for loading an ApplicationContext.

If not specified, the loader will be inherited from the first superclass which is annotated with @ContextConfiguration and specifies an explicit loader. If no class in the hierarchy specifies an explicit loader, a default loader will be used instead.

The default concrete implementation chosen at runtime will be GenericXmlContextLoader. Also check out AbstractContextLoader's javadoc for details on the default behavior there.

Default:
org.springframework.test.context.ContextLoader.class