接口 SmartContextLoader
- 所有超级接口:
ContextLoader
- 所有已知实现类:
AbstractContextLoader,AbstractDelegatingSmartContextLoader,AbstractGenericContextLoader,AbstractGenericWebContextLoader,AnnotationConfigContextLoader,AnnotationConfigWebContextLoader,DelegatingSmartContextLoader,GenericGroovyXmlContextLoader,GenericGroovyXmlWebContextLoader,GenericPropertiesContextLoader,GenericXmlContextLoader,GenericXmlWebContextLoader,WebDelegatingSmartContextLoader
public interface SmartContextLoader extends ContextLoader
Strategy interface for loading anapplication contextfor an integration test managed by the Spring TestContext Framework.The
SmartContextLoaderSPI supersedes theContextLoaderSPI introduced in Spring 2.5: aSmartContextLoadercan choose to process either resource locations or annotated classes. Furthermore, aSmartContextLoadercan set active bean definition profiles in the context that it loads (seeMergedContextConfiguration.getActiveProfiles()andloadContext(MergedContextConfiguration)).See the Javadoc for
@ContextConfigurationfor a definition of annotated class.Clients of a
SmartContextLoadershould callprocessContextConfiguration()prior to callingloadContext(). This gives aSmartContextLoaderthe 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
SmartContextLoaderextendsContextLoader, clients should favorSmartContextLoader-specific methods over those defined inContextLoader, particularly because aSmartContextLoadermay choose not to support methods defined in theContextLoaderSPI.Concrete implementations must provide a
publicno-args constructor.Spring provides the following out-of-the-box implementations:
- 从以下版本开始:
- 3.1
- 作者:
- Sam Brannen
- 另请参阅:
ContextConfiguration,ActiveProfiles,ContextConfigurationAttributes,MergedContextConfiguration
方法概要
所有方法 实例方法 抽象方法 修饰符和类型 方法 说明 ApplicationContextloadContext(MergedContextConfiguration mergedConfig)Loads a newcontextbased on the suppliedmerged context configuration, configures the context, and finally returns the context in a fully refreshed state.voidprocessContextConfiguration(ContextConfigurationAttributes configAttributes)Processes theContextConfigurationAttributesfor a given test class.从接口继承的方法 org.springframework.test.context.ContextLoader
loadContext, processLocations
方法详细资料
processContextConfiguration
void processContextConfiguration(ContextConfigurationAttributes configAttributes)
Processes theContextConfigurationAttributesfor a given test class.Concrete implementations may choose to modify the
locationsorclassesin the suppliedContextConfigurationAttributes, generate default configuration locations, or detect default configuration classes if the supplied values arenullor empty.Note: in contrast to a standard
ContextLoader, aSmartContextLoadermustpreemptively verify that a generated or detected default actually exists before setting the correspondinglocationsorclassesproperty in the suppliedContextConfigurationAttributes. Consequently, leaving thelocationsorclassesproperty empty signals that thisSmartContextLoaderwas not able to generate or detect defaults.- 参数:
configAttributes- the context configuration attributes to process
loadContext
ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception
Loads a newcontextbased 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 contextsloaded 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
ApplicationContextloaded by aSmartContextLoadermust 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).- 参数:
mergedConfig- the merged context configuration to use to load the application context- 返回:
- a new application context
- 抛出:
Exception- if context loading failed- 另请参阅:
processContextConfiguration(ContextConfigurationAttributes),#registerAnnotationConfigProcessors(org.springframework.beans.factory.support.BeanDefinitionRegistry),MergedContextConfiguration.getActiveProfiles(),ConfigurableApplicationContext.getEnvironment()