类 DefaultCacheAwareContextLoaderDelegate
- java.lang.Object
- org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate
- 所有已实现的接口:
CacheAwareContextLoaderDelegate
public class DefaultCacheAwareContextLoaderDelegate extends Object implements CacheAwareContextLoaderDelegate
Default implementation of theCacheAwareContextLoaderDelegateinterface.To use a static
DefaultContextCache, invoke theDefaultCacheAwareContextLoaderDelegate()constructor; otherwise, invoke theDefaultCacheAwareContextLoaderDelegate(ContextCache)and provide a customContextCacheimplementation.- 从以下版本开始:
- 4.1
- 作者:
- Sam Brannen
构造器概要
构造器 构造器 说明 DefaultCacheAwareContextLoaderDelegate()Construct a newDefaultCacheAwareContextLoaderDelegateusing a staticDefaultContextCache.DefaultCacheAwareContextLoaderDelegate(ContextCache contextCache)Construct a newDefaultCacheAwareContextLoaderDelegateusing the suppliedContextCache.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 voidcloseContext(MergedContextConfiguration mergedContextConfiguration, DirtiesContext.HierarchyMode hierarchyMode)Remove the application context for the suppliedMergedContextConfigurationfrom theContextCacheand close it if it is an instance ofConfigurableApplicationContext.protected ContextCachegetContextCache()Get theContextCacheused by this context loader delegate.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.protected ApplicationContextloadContextInternal(MergedContextConfiguration mergedContextConfiguration)Load theApplicationContextfor the supplied merged context configuration.
构造器详细资料
DefaultCacheAwareContextLoaderDelegate
public DefaultCacheAwareContextLoaderDelegate()
Construct a newDefaultCacheAwareContextLoaderDelegateusing a staticDefaultContextCache.This default cache is static so that each context can be cached and reused for all subsequent tests that declare the same unique context configuration within the same JVM process.
DefaultCacheAwareContextLoaderDelegate
public DefaultCacheAwareContextLoaderDelegate(ContextCache contextCache)
Construct a newDefaultCacheAwareContextLoaderDelegateusing the suppliedContextCache.
方法详细资料
getContextCache
protected ContextCache getContextCache()
Get theContextCacheused by this context loader delegate.
loadContextInternal
protected ApplicationContext loadContextInternal(MergedContextConfiguration mergedContextConfiguration) throws Exception
Load theApplicationContextfor the supplied merged context configuration.Supports both the
SmartContextLoaderandContextLoaderSPIs.- 抛出:
Exception- if an error occurs while loading the application context
isContextLoaded
public boolean isContextLoaded(MergedContextConfiguration mergedContextConfiguration)
从接口复制的说明:CacheAwareContextLoaderDelegateDetermine 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.- 指定者:
isContextLoaded在接口中CacheAwareContextLoaderDelegate- 参数:
mergedContextConfiguration- the merged context configuration used to load the application context; nevernull- 返回:
trueif the application context has been loaded- 另请参阅:
CacheAwareContextLoaderDelegate.loadContext(org.springframework.test.context.MergedContextConfiguration),CacheAwareContextLoaderDelegate.closeContext(org.springframework.test.context.MergedContextConfiguration, org.springframework.test.annotation.DirtiesContext.HierarchyMode)
loadContext
public ApplicationContext loadContext(MergedContextConfiguration mergedContextConfiguration)
从接口复制的说明:CacheAwareContextLoaderDelegateLoad 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().- 指定者:
loadContext在接口中CacheAwareContextLoaderDelegate- 参数:
mergedContextConfiguration- the merged context configuration to use to load the application context; nevernull- 返回:
- the application context (never
null) - 另请参阅:
CacheAwareContextLoaderDelegate.isContextLoaded(org.springframework.test.context.MergedContextConfiguration),CacheAwareContextLoaderDelegate.closeContext(org.springframework.test.context.MergedContextConfiguration, org.springframework.test.annotation.DirtiesContext.HierarchyMode)
closeContext
public void closeContext(MergedContextConfiguration mergedContextConfiguration, @Nullable DirtiesContext.HierarchyMode hierarchyMode)
从接口复制的说明:CacheAwareContextLoaderDelegateRemove 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.
- 指定者:
closeContext在接口中CacheAwareContextLoaderDelegate- 参数:
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- 另请参阅:
CacheAwareContextLoaderDelegate.isContextLoaded(org.springframework.test.context.MergedContextConfiguration),CacheAwareContextLoaderDelegate.loadContext(org.springframework.test.context.MergedContextConfiguration)