Class AbstractDelegatingSmartContextLoader

java.lang.Object
org.springframework.test.context.support.AbstractDelegatingSmartContextLoader
All Implemented Interfaces:
AotContextLoader, ContextLoader, SmartContextLoader
Direct Known Subclasses:
DelegatingSmartContextLoader, WebDelegatingSmartContextLoader

public abstract class AbstractDelegatingSmartContextLoader extends Object implements AotContextLoader
AbstractDelegatingSmartContextLoader serves as an abstract base class for implementations of the SmartContextLoader SPI that delegate to a set of candidate SmartContextLoaders (i.e., one that supports XML configuration files or Groovy scripts and one that supports annotated classes) to determine which context loader is appropriate for a given test class's configuration. Each candidate is given a chance to process the ContextConfigurationAttributes for each class in the test class hierarchy and enclosing class hierarchy that is annotated with @ContextConfiguration, and the candidate that supports the merged, processed configuration will be used to actually load the context.

Any reference to an XML-based loader can be interpreted to mean a context loader that supports only XML configuration files or one that supports both XML configuration files and Groovy scripts simultaneously.

Placing an empty @ContextConfiguration annotation on a test class signals that default resource locations (for example, XML configuration files or Groovy scripts) or default configuration classes should be detected. Furthermore, if a specific ContextLoader or SmartContextLoader is not explicitly declared via @ContextConfiguration, a concrete subclass of AbstractDelegatingSmartContextLoader will be used as the default loader, thus providing automatic support for either path-based resource locations (for example, XML configuration files and Groovy scripts) or annotated classes, but not both simultaneously.

A test class may optionally declare neither path-based resource locations nor annotated classes and instead declare only application context initializers. In such cases, an attempt will still be made to detect defaults, but their absence will not result in an exception.

As of Spring Framework 6.0, this class implements AotContextLoader. Consequently, the candidate getXmlLoader() and getAnnotationConfigLoader() must also implement AotContextLoader in order to provide AOT support.

Since:
3.2
Author:
Sam Brannen, Phillip Webb
See Also: