Interface SmartContextLoader
- All Superinterfaces:
ContextLoader
- All Known Implementing Classes:
AbstractContextLoader
,AbstractDelegatingSmartContextLoader
,AbstractGenericContextLoader
,AbstractGenericWebContextLoader
,AnnotationConfigContextLoader
,AnnotationConfigWebContextLoader
,DelegatingSmartContextLoader
,GenericGroovyXmlContextLoader
,GenericGroovyXmlWebContextLoader
,GenericPropertiesContextLoader
,GenericXmlContextLoader
,GenericXmlWebContextLoader
,WebDelegatingSmartContextLoader
public interface SmartContextLoader extends ContextLoader
Strategy interface for loading anapplication context
for an integration test managed by the Spring TestContext Framework.The
SmartContextLoader
SPI supersedes theContextLoader
SPI introduced in Spring 2.5: aSmartContextLoader
can choose to process either resource locations or annotated classes. Furthermore, aSmartContextLoader
can set active bean definition profiles in the context that it loads (seeMergedContextConfiguration.getActiveProfiles()
andloadContext(MergedContextConfiguration)
).See the Javadoc for
@ContextConfiguration
for a definition of annotated class.Clients of a
SmartContextLoader
should callprocessContextConfiguration()
prior to callingloadContext()
. This gives aSmartContextLoader
the opportunity to provide custom support for modifying resource locations or detecting default resource locations or default configuration classes. The results ofprocessContextConfiguration()
should be merged for all classes in the hierarchy of the root test class and then supplied toloadContext()
.Even though
SmartContextLoader
extendsContextLoader
, clients should favorSmartContextLoader
-specific methods over those defined inContextLoader
, particularly because aSmartContextLoader
may choose not to support methods defined in theContextLoader
SPI.Concrete implementations must provide a
public
no-args constructor.Spring provides the following out-of-the-box implementations:
- Since:
- 3.1
- Author:
- Sam Brannen
- See Also:
ContextConfiguration
,ActiveProfiles
,ContextConfigurationAttributes
,MergedContextConfiguration
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description ApplicationContext
loadContext(MergedContextConfiguration mergedConfig)
Loads a newcontext
based on the suppliedmerged context configuration
, configures the context, and finally returns the context in a fully refreshed state.void
processContextConfiguration(ContextConfigurationAttributes configAttributes)
Processes theContextConfigurationAttributes
for a given test class.Methods inherited from interface org.springframework.test.context.ContextLoader
loadContext, processLocations
Method Detail
processContextConfiguration
void processContextConfiguration(ContextConfigurationAttributes configAttributes)
Processes theContextConfigurationAttributes
for a given test class.Concrete implementations may choose to modify the
locations
orclasses
in the suppliedContextConfigurationAttributes
, generate default configuration locations, or detect default configuration classes if the supplied values arenull
or empty.Note: in contrast to a standard
ContextLoader
, aSmartContextLoader
mustpreemptively verify that a generated or detected default actually exists before setting the correspondinglocations
orclasses
property in the suppliedContextConfigurationAttributes
. Consequently, leaving thelocations
orclasses
property empty signals that thisSmartContextLoader
was not able to generate or detect defaults.- Parameters:
configAttributes
- the context configuration attributes to process
loadContext
ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception
Loads a newcontext
based on the suppliedmerged context configuration
, configures the context, and finally returns the context in a fully refreshed state.Concrete implementations should register annotation configuration processors with bean factories of
application contexts
loaded by thisSmartContextLoader
. Beans will therefore automatically be candidates for annotation-based dependency injection using@Autowired
,@Resource
, and@Inject
. In addition, concrete implementations should set the active bean definition profiles in the context'sEnvironment
.Any
ApplicationContext
loaded by aSmartContextLoader
must register a JVM shutdown hook for itself. Unless the context gets closed early, all context instances will be automatically closed on JVM shutdown. This allows for freeing of external resources held by beans within the context (e.g., temporary files).- Parameters:
mergedConfig
- the merged context configuration to use to load the application context- Returns:
- a new application context
- Throws:
Exception
- if context loading failed- See Also:
processContextConfiguration(ContextConfigurationAttributes)
,#registerAnnotationConfigProcessors(org.springframework.beans.factory.support.BeanDefinitionRegistry)
,MergedContextConfiguration.getActiveProfiles()
,ConfigurableApplicationContext.getEnvironment()