接口 CacheAwareContextLoaderDelegate
CacheAwareContextLoaderDelegate is responsible for loading and closing application
contexts, interacting transparently with a
ContextCache
behind the scenes.
Note: CacheAwareContextLoaderDelegate does not extend the
ContextLoader or SmartContextLoader interface.
- 从以下版本开始:
- 4.0
- 作者:
- Sam Brannen, Harry Yang
-
字段概要
字段修饰符和类型字段说明static final StringSystem property used to configure the failure threshold for errors encountered while attempting to load an application context: "infra.test.context.failure.threshold".static final StringSystem property used to configure the fully qualified class name of the defaultCacheAwareContextLoaderDelegate.static final intThe default failure threshold for errors encountered while attempting to load an application context: 1. -
方法概要
修饰符和类型方法说明voidcloseContext(MergedContextConfiguration mergedContextConfiguration, DirtiesContext.HierarchyMode hierarchyMode) Remove the application context for the suppliedMergedContextConfigurationfrom theContextCacheand close it if it is an instance ofConfigurableApplicationContext.default booleanisContextLoaded(MergedContextConfiguration mergedContextConfiguration) Determine if the application context for the suppliedMergedContextConfigurationhas been loaded (i.e., is present in theContextCache).cn.taketoday.context.ApplicationContextloadContext(MergedContextConfiguration mergedConfig) Load the application context for the suppliedMergedContextConfigurationby delegating to theContextLoaderconfigured in the givenMergedContextConfiguration.
-
字段详细资料
-
DEFAULT_CONTEXT_FAILURE_THRESHOLD
static final int DEFAULT_CONTEXT_FAILURE_THRESHOLDThe default failure threshold for errors encountered while attempting to load an application context: 1. -
CONTEXT_FAILURE_THRESHOLD_PROPERTY_NAME
System property used to configure the failure threshold for errors encountered while attempting to load an application context: "infra.test.context.failure.threshold".May alternatively be configured via the
TodayStrategiesmechanism.Implementations of
CacheAwareContextLoaderDelegateare not required to support this feature. Consult the documentation of the corresponding implementation for details. Note, however, that the standardCacheAwareContextLoaderDelegateimplementation in Infra supports this feature. -
DEFAULT_CACHE_AWARE_CONTEXT_LOADER_DELEGATE_PROPERTY_NAME
System property used to configure the fully qualified class name of the defaultCacheAwareContextLoaderDelegate.May alternatively be configured via the
TodayStrategiesmechanism.If this property is not defined, the
DefaultCacheAwareContextLoaderDelegatewill be used as the default.- 另请参阅:
-
-
方法详细资料
-
isContextLoaded
Determine if the application context for the suppliedMergedContextConfigurationhas been loaded (i.e., is present in theContextCache).Implementations of this method must not load the application context as a side effect. In addition, implementations of this method should not log the cache statistics via
ContextCache.logStatistics().The default implementation of this method always returns
false. CustomCacheAwareContextLoaderDelegateimplementations are therefore highly encouraged to override this method with a more meaningful implementation. Note that the standardCacheAwareContextLoaderDelegateimplementation in Infra overrides this method appropriately.- 参数:
mergedContextConfiguration- the merged context configuration used to load the application context; nevernull- 返回:
trueif the application context has been loaded- 另请参阅:
-
loadContext
Load the application context for the suppliedMergedContextConfigurationby delegating to theContextLoaderconfigured in the givenMergedContextConfiguration.If the context is present in the
ContextCacheit will simply be returned; otherwise, it will be loaded, stored in the cache, and returned.Implementations of this method should load
ApplicationContextFailureProcessorimplementations via theTodayStrategiesmechanism, catch any exception thrown by theContextLoader, and delegate to each of the configured failure processors to process the context load failure if the exception is an instance ofContextLoadException.Implementations of this method are encouraged to support the failure threshold feature. Specifically, if repeated attempts are made to load an application context and that application context consistently fails to load — for example, due to a configuration error that prevents the context from successfully loading — this method should preemptively throw an
IllegalStateExceptionif the configured failure threshold has been exceeded. Note that theContextCacheprovides support for tracking and incrementing the failure count for a given context cache key.The cache statistics should be logged by invoking
ContextCache.logStatistics().- 参数:
mergedConfig- the merged context configuration to use to load the application context; nevernull- 返回:
- the application context (never
null) - 抛出:
IllegalStateException- if an error occurs while retrieving or loading the application context- 另请参阅:
-
closeContext
void closeContext(MergedContextConfiguration mergedContextConfiguration, @Nullable DirtiesContext.HierarchyMode hierarchyMode) Remove the application context for the suppliedMergedContextConfigurationfrom theContextCacheand close it if it is an instance ofConfigurableApplicationContext.The semantics of the supplied
HierarchyModemust be honored when removing the context from the cache. See the Javadoc forDirtiesContext.HierarchyModefor details.Generally speaking, this method should only be called if the state of a singleton bean has been changed (potentially affecting future interaction with the context) or if the context needs to be prematurely removed from the cache.
- 参数:
mergedContextConfiguration- the merged context configuration for the application context to close; nevernullhierarchyMode- the hierarchy mode; may benullif the context is not part of a hierarchy- 另请参阅:
-