class DefaultCacheAwareContextLoaderDelegate extends java.lang.Object implements CacheAwareContextLoaderDelegate
CacheAwareContextLoaderDelegate
interface.
Although DefaultCacheAwareContextLoaderDelegate
was first introduced
in Spring Framework 4.1, the initial implementation of this class was extracted
from the existing code base for CacheAwareContextLoaderDelegate
when
CacheAwareContextLoaderDelegate
was converted into an interface.
Modifier and Type | Field and Description |
---|---|
private ContextCache |
contextCache |
private static Log |
logger |
private static Log |
statsLogger |
Constructor and Description |
---|
DefaultCacheAwareContextLoaderDelegate(ContextCache contextCache) |
Modifier and Type | Method and Description |
---|---|
void |
closeContext(MergedContextConfiguration mergedContextConfiguration,
DirtiesContext.HierarchyMode hierarchyMode)
Remove the application context for the
supplied
MergedContextConfiguration from the context cache
and close it if it is
an instance of ConfigurableApplicationContext . |
ApplicationContext |
loadContext(MergedContextConfiguration mergedContextConfiguration)
Load the application context for the supplied
MergedContextConfiguration by delegating to the ContextLoader
configured in the given MergedContextConfiguration . |
private ApplicationContext |
loadContextInternal(MergedContextConfiguration mergedContextConfiguration)
Load the
ApplicationContext for the supplied merged context configuration. |
private static final Log logger
private static final Log statsLogger
private final ContextCache contextCache
DefaultCacheAwareContextLoaderDelegate(ContextCache contextCache)
private ApplicationContext loadContextInternal(MergedContextConfiguration mergedContextConfiguration) throws java.lang.Exception
ApplicationContext
for the supplied merged context configuration.
Supports both the SmartContextLoader
and ContextLoader
SPIs.
java.lang.Exception
- if an error occurs while loading the application contextpublic ApplicationContext loadContext(MergedContextConfiguration mergedContextConfiguration)
CacheAwareContextLoaderDelegate
MergedContextConfiguration
by delegating to the ContextLoader
configured in the given MergedContextConfiguration
.
If the context is present in the context cache it will simply be returned; otherwise, it will be loaded, stored in the cache, and returned.
loadContext
in interface CacheAwareContextLoaderDelegate
mergedContextConfiguration
- the merged context configuration to use
to load the application context; never null
public void closeContext(MergedContextConfiguration mergedContextConfiguration, DirtiesContext.HierarchyMode hierarchyMode)
CacheAwareContextLoaderDelegate
MergedContextConfiguration
from the context cache
and close it if it is
an instance of ConfigurableApplicationContext
.
The semantics of the supplied HierarchyMode
must be honored when
removing the context from the cache. See the Javadoc for DirtiesContext.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
in interface CacheAwareContextLoaderDelegate
mergedContextConfiguration
- the merged context configuration for the
application context to close; never null
hierarchyMode
- the hierarchy mode; may be null
if the context
is not part of a hierarchy