Interface CacheAwareContextLoaderDelegate
- All Known Implementing Classes:
- DefaultCacheAwareContextLoaderDelegate
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.
- Since:
- 3.2.2
- Author:
- Sam Brannen
- 
Method SummaryModifier and TypeMethodDescriptionvoidcloseContext(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).loadContext(MergedContextConfiguration mergedContextConfiguration) Load the application context for the suppliedMergedContextConfigurationby delegating to theContextLoaderconfigured in the givenMergedContextConfiguration.default voidsetContextFailureProcessor(ApplicationContextFailureProcessor contextFailureProcessor) Set theApplicationContextFailureProcessorto use.
- 
Method Details- 
isContextLoadedDetermine 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.- Parameters:
- mergedContextConfiguration- the merged context configuration used to load the application context; never- null
- Returns:
- trueif the application context has been loaded
- Since:
- 5.2
- See Also:
 
- 
loadContextLoad 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().- Parameters:
- mergedContextConfiguration- the merged context configuration to use to load the application context; never- null
- Returns:
- the application context (never null)
- Throws:
- IllegalStateException- if an error occurs while retrieving or loading the application context
- See Also:
- 
- isContextLoaded(org.springframework.test.context.MergedContextConfiguration)
- closeContext(org.springframework.test.context.MergedContextConfiguration, org.springframework.test.annotation.DirtiesContext.HierarchyMode)
- setContextFailureProcessor(org.springframework.test.context.ApplicationContextFailureProcessor)
 
 
- 
closeContextvoid 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. - Parameters:
- mergedContextConfiguration- the merged context configuration for the application context to close; never- null
- hierarchyMode- the hierarchy mode; may be- nullif the context is not part of a hierarchy
- Since:
- 4.1
- See Also:
 
- 
setContextFailureProcessorSet theApplicationContextFailureProcessorto use.The default implementation ignores the supplied processor. Concrete implementations should override this method to store a reference to the supplied processor and use it to process ContextLoadExceptionsthrown from context loaders inloadContext(MergedContextConfiguration).- Parameters:
- contextFailureProcessor- the context failure processor to use
- Since:
- 6.0
 
 
-