类 AbstractDelegatingSmartContextLoader
- 所有已实现的接口:
AotContextLoader,ContextLoader,SmartContextLoader
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
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 (e.g., 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
(e.g., 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.
- 从以下版本开始:
- 4.0
- 作者:
- Sam Brannen, Phillip Webb, Harry Yang
- 另请参阅:
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明private static voiddelegateProcessing(SmartContextLoader loader, ContextConfigurationAttributes configAttributes) protected abstract SmartContextLoaderGet the delegateSmartContextLoaderthat supports annotated classes.private AotContextLoadergetAotContextLoader(MergedContextConfiguration mergedConfig) private SmartContextLoadergetContextLoader(MergedContextConfiguration mergedConfig) protected abstract SmartContextLoaderGet the delegateSmartContextLoaderthat supports XML configuration files and/or Groovy scripts.private static booleanhasInitializersOrCustomizers(MergedContextConfiguration mergedConfig) final cn.taketoday.context.ApplicationContextloadContext(MergedContextConfiguration mergedConfig) Delegates to an appropriate candidateSmartContextLoaderto load anApplicationContext.final cn.taketoday.context.ApplicationContextloadContextForAotProcessing(MergedContextConfiguration mergedConfig) Delegates to an appropriate candidateSmartContextLoaderto load anApplicationContextfor AOT processing.final cn.taketoday.context.ApplicationContextloadContextForAotRuntime(MergedContextConfiguration mergedConfig, cn.taketoday.context.ApplicationContextInitializer initializer) Delegates to an appropriate candidateSmartContextLoaderto load anApplicationContextfor AOT run-time execution.private static Stringname(SmartContextLoader loader) voidprocessContextConfiguration(ContextConfigurationAttributes configAttributes) Delegates to candidateSmartContextLoadersto process the suppliedContextConfigurationAttributes.private booleansupports(SmartContextLoader loader, MergedContextConfiguration mergedConfig) 从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 cn.taketoday.test.context.SmartContextLoader
loadContext, processLocations
-
字段详细资料
-
logger
private static final cn.taketoday.logging.Logger logger
-
-
构造器详细资料
-
AbstractDelegatingSmartContextLoader
public AbstractDelegatingSmartContextLoader()
-
-
方法详细资料
-
getXmlLoader
Get the delegateSmartContextLoaderthat supports XML configuration files and/or Groovy scripts. -
getAnnotationConfigLoader
Get the delegateSmartContextLoaderthat supports annotated classes. -
processContextConfiguration
Delegates to candidateSmartContextLoadersto process the suppliedContextConfigurationAttributes.Delegation is based on explicit knowledge of the implementations of the default loaders for XML configuration files and Groovy scripts and annotated classes. Specifically, the delegation algorithm is as follows:
- If the resource locations or annotated classes in the supplied
ContextConfigurationAttributesare not empty, the appropriate candidate loader will be allowed to process the configuration as is, without any checks for detection of defaults. - Otherwise, the XML-based loader will be allowed to process
the configuration in order to detect default resource locations. If
the XML-based loader detects default resource locations,
an
infomessage will be logged. - Subsequently, the annotation-based loader will be allowed to
process the configuration in order to detect default configuration classes.
If the annotation-based loader detects default configuration
classes, an
infomessage will be logged.
- 指定者:
processContextConfiguration在接口中SmartContextLoader- 参数:
configAttributes- the context configuration attributes to process- 抛出:
IllegalArgumentException- if the supplied configuration attributes arenull, or if the supplied configuration attributes include both resource locations and annotated classesIllegalStateException- if the XML-based loader detects default configuration classes; if the annotation-based loader detects default resource locations; if neither candidate loader detects defaults for the supplied context configuration; or if both candidate loaders detect defaults for the supplied context configuration
- If the resource locations or annotated classes in the supplied
-
loadContext
public final cn.taketoday.context.ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception Delegates to an appropriate candidateSmartContextLoaderto load anApplicationContext.Delegation is based on explicit knowledge of the implementations of the default loaders for XML configuration files and Groovy scripts and annotated classes. Specifically, the delegation algorithm is as follows:
- If the resource locations in the supplied
MergedContextConfigurationare not empty and the annotated classes are empty, the XML-based loader will load theApplicationContext. - If the annotated classes in the supplied
MergedContextConfigurationare not empty and the resource locations are empty, the annotation-based loader will load theApplicationContext.
- 指定者:
loadContext在接口中SmartContextLoader- 参数:
mergedConfig- the merged context configuration to use to load the application context- 返回:
- a new application context
- 抛出:
IllegalStateException- if neither candidate loader is capable of loading anApplicationContextfrom the supplied merged context configurationContextLoadException- if context loading failedException- 另请参阅:
-
SmartContextLoader.processContextConfiguration(ContextConfigurationAttributes)AnnotationConfigUtils.registerAnnotationConfigProcessors(cn.taketoday.beans.factory.support.BeanDefinitionRegistry)ConfigurableApplicationContext.getEnvironment()
- If the resource locations in the supplied
-
loadContextForAotProcessing
public final cn.taketoday.context.ApplicationContext loadContextForAotProcessing(MergedContextConfiguration mergedConfig) throws Exception Delegates to an appropriate candidateSmartContextLoaderto load anApplicationContextfor AOT processing.Delegation is based on explicit knowledge of the implementations of the default loaders. See
loadContext(MergedContextConfiguration)for details.- 指定者:
loadContextForAotProcessing在接口中AotContextLoader- 参数:
mergedConfig- the merged context configuration to use to load the application context- 返回:
- a new application context
- 抛出:
IllegalArgumentException- if the supplied merged configuration isnullIllegalStateException- if neither candidate loader is capable of loading anApplicationContextfrom the supplied merged context configurationContextLoadException- if context loading failedException- 另请参阅:
-
loadContextForAotRuntime
public final cn.taketoday.context.ApplicationContext loadContextForAotRuntime(MergedContextConfiguration mergedConfig, cn.taketoday.context.ApplicationContextInitializer initializer) throws Exception Delegates to an appropriate candidateSmartContextLoaderto load anApplicationContextfor AOT run-time execution.Delegation is based on explicit knowledge of the implementations of the default loaders. See
loadContext(MergedContextConfiguration)for details.- 指定者:
loadContextForAotRuntime在接口中AotContextLoader- 参数:
mergedConfig- the merged context configuration to use to load the application contextinitializer- theApplicationContextInitializerthat should be applied to the context in order to recreate bean definitions- 返回:
- a new application context
- 抛出:
IllegalStateException- if neither candidate loader is capable of loading anApplicationContextfrom the supplied merged context configurationContextLoadException- if context loading failedException- 另请参阅:
-
getContextLoader
-
getAotContextLoader
-
supports
-
delegateProcessing
private static void delegateProcessing(SmartContextLoader loader, ContextConfigurationAttributes configAttributes) -
hasInitializersOrCustomizers
-
name
-