类 DefaultCacheAwareContextLoaderDelegate
- java.lang.Object
- org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate
- 所有已实现的接口:
CacheAwareContextLoaderDelegate
public class DefaultCacheAwareContextLoaderDelegate extends Object implements CacheAwareContextLoaderDelegate
Default implementation of theCacheAwareContextLoaderDelegate
interface.To use a static
DefaultContextCache
, invoke theDefaultCacheAwareContextLoaderDelegate()
constructor; otherwise, invoke theDefaultCacheAwareContextLoaderDelegate(ContextCache)
and provide a customContextCache
implementation.- 从以下版本开始:
- 4.1
- 作者:
- Sam Brannen
构造器概要
构造器 构造器 说明 DefaultCacheAwareContextLoaderDelegate()
Construct a newDefaultCacheAwareContextLoaderDelegate
using a staticDefaultContextCache
.DefaultCacheAwareContextLoaderDelegate(ContextCache contextCache)
Construct a newDefaultCacheAwareContextLoaderDelegate
using the suppliedContextCache
.
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 void
closeContext(MergedContextConfiguration mergedContextConfiguration, DirtiesContext.HierarchyMode hierarchyMode)
Remove the application context for the suppliedMergedContextConfiguration
from theContextCache
and close it if it is an instance ofConfigurableApplicationContext
.protected ContextCache
getContextCache()
Get theContextCache
used by this context loader delegate.boolean
isContextLoaded(MergedContextConfiguration mergedContextConfiguration)
Determine if the application context for the suppliedMergedContextConfiguration
has been loaded (i.e., is present in theContextCache
).ApplicationContext
loadContext(MergedContextConfiguration mergedContextConfiguration)
Load the application context for the suppliedMergedContextConfiguration
by delegating to theContextLoader
configured in the givenMergedContextConfiguration
.protected ApplicationContext
loadContextInternal(MergedContextConfiguration mergedContextConfiguration)
Load theApplicationContext
for the supplied merged context configuration.
构造器详细资料
DefaultCacheAwareContextLoaderDelegate
public DefaultCacheAwareContextLoaderDelegate()
Construct a newDefaultCacheAwareContextLoaderDelegate
using 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 newDefaultCacheAwareContextLoaderDelegate
using the suppliedContextCache
.
方法详细资料
getContextCache
protected ContextCache getContextCache()
Get theContextCache
used by this context loader delegate.
loadContextInternal
protected ApplicationContext loadContextInternal(MergedContextConfiguration mergedContextConfiguration) throws Exception
Load theApplicationContext
for the supplied merged context configuration.Supports both the
SmartContextLoader
andContextLoader
SPIs.- 抛出:
Exception
- if an error occurs while loading the application context
isContextLoaded
public boolean isContextLoaded(MergedContextConfiguration mergedContextConfiguration)
从接口复制的说明:CacheAwareContextLoaderDelegate
Determine if the application context for the suppliedMergedContextConfiguration
has 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
. CustomCacheAwareContextLoaderDelegate
implementations are therefore highly encouraged to override this method with a more meaningful implementation. Note that the standardCacheAwareContextLoaderDelegate
implementation in Spring overrides this method appropriately.- 指定者:
isContextLoaded
在接口中CacheAwareContextLoaderDelegate
- 参数:
mergedContextConfiguration
- the merged context configuration used to load the application context; nevernull
- 返回:
true
if 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)
从接口复制的说明:CacheAwareContextLoaderDelegate
Load the application context for the suppliedMergedContextConfiguration
by delegating to theContextLoader
configured in the givenMergedContextConfiguration
.If the context is present in the
ContextCache
it 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)
从接口复制的说明:CacheAwareContextLoaderDelegate
Remove the application context for the suppliedMergedContextConfiguration
from theContextCache
and close it if it is an instance ofConfigurableApplicationContext
.The semantics of the supplied
HierarchyMode
must be honored when removing the context from the cache. See the Javadoc forDirtiesContext.HierarchyMode
for 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; nevernull
hierarchyMode
- the hierarchy mode; may benull
if the context is not part of a hierarchy- 另请参阅:
CacheAwareContextLoaderDelegate.isContextLoaded(org.springframework.test.context.MergedContextConfiguration)
,CacheAwareContextLoaderDelegate.loadContext(org.springframework.test.context.MergedContextConfiguration)