接口 CacheAwareContextLoaderDelegate
public interface CacheAwareContextLoaderDelegate
ACacheAwareContextLoaderDelegateis responsible for loading and closing application contexts, interacting transparently with aContextCachebehind the scenes.Note:
CacheAwareContextLoaderDelegatedoes not extend theContextLoaderorSmartContextLoaderinterface.- 从以下版本开始:
- 3.2.2
- 作者:
- Sam Brannen
方法概要
所有方法 实例方法 抽象方法 默认方法 修饰符和类型 方法 说明 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).ApplicationContextloadContext(MergedContextConfiguration mergedContextConfiguration)Load the application context for the suppliedMergedContextConfigurationby delegating to theContextLoaderconfigured in the givenMergedContextConfiguration.
方法详细资料
isContextLoaded
default boolean isContextLoaded(MergedContextConfiguration mergedContextConfiguration)
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 Spring overrides this method appropriately.- 参数:
mergedContextConfiguration- the merged context configuration used to load the application context; nevernull- 返回:
trueif the application context has been loaded- 从以下版本开始:
- 5.2
- 另请参阅:
loadContext(org.springframework.test.context.MergedContextConfiguration),closeContext(org.springframework.test.context.MergedContextConfiguration, org.springframework.test.annotation.DirtiesContext.HierarchyMode)
loadContext
ApplicationContext loadContext(MergedContextConfiguration mergedContextConfiguration)
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.The cache statistics should be logged by invoking
ContextCache.logStatistics().- 参数:
mergedContextConfiguration- 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- 另请参阅:
isContextLoaded(org.springframework.test.context.MergedContextConfiguration),closeContext(org.springframework.test.context.MergedContextConfiguration, org.springframework.test.annotation.DirtiesContext.HierarchyMode)
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- 从以下版本开始:
- 4.1
- 另请参阅:
isContextLoaded(org.springframework.test.context.MergedContextConfiguration),loadContext(org.springframework.test.context.MergedContextConfiguration)