接口 SmartContextLoader
- 所有超级接口:
ContextLoader
- 所有已知子接口:
AotContextLoader
- 所有已知实现类:
AbstractContextLoader,AbstractDelegatingSmartContextLoader,AbstractGenericContextLoader,AbstractGenericWebContextLoader,AnnotationConfigContextLoader,AnnotationConfigWebContextLoader,DelegatingSmartContextLoader,GenericPropertiesContextLoader,GenericXmlContextLoader,GenericXmlWebContextLoader,InfraApplicationContextLoader,WebDelegatingSmartContextLoader
application context
for an integration test managed by the TestContext Framework.
The SmartContextLoader SPI supersedes the ContextLoader SPI
introduced a SmartContextLoader can choose to process
either resource locations or annotated classes. Furthermore, a
SmartContextLoader can set active bean definition profiles in the
context that it loads (see MergedContextConfiguration.getActiveProfiles()
and loadContext(MergedContextConfiguration)).
See the Javadoc for @ContextConfiguration
for a definition of annotated class.
Clients of a SmartContextLoader should call
processContextConfiguration() prior to calling
loadContext(). This gives a
SmartContextLoader the opportunity to provide custom support for
modifying resource locations or detecting default resource locations or
default configuration classes. The results of
processContextConfiguration() should be merged for all classes in the
hierarchy of the root test class and then supplied to
loadContext().
Even though SmartContextLoader extends ContextLoader,
clients should favor SmartContextLoader-specific methods over those
defined in ContextLoader, particularly because a
SmartContextLoader may choose not to support methods defined in the
ContextLoader SPI.
Concrete implementations must provide a public no-args constructor.
provides the following out-of-the-box implementations:
- 从以下版本开始:
- 4.0
- 作者:
- Sam Brannen, Harry Yang
- 另请参阅:
-
方法概要
修饰符和类型方法说明cn.taketoday.context.ApplicationContextloadContext(MergedContextConfiguration mergedConfig) Load a newApplicationContextbased on the suppliedMergedContextConfiguration, configure the context, and return the context in a fully refreshed state.default cn.taketoday.context.ApplicationContextloadContext(String... locations) SmartContextLoaderdoes not support deprecatedContextLoadermethods.voidprocessContextConfiguration(ContextConfigurationAttributes configAttributes) Process theContextConfigurationAttributesfor a given test class.default String[]processLocations(Class<?> clazz, String... locations) SmartContextLoaderdoes not support deprecatedContextLoadermethods.
-
方法详细资料
-
processContextConfiguration
Process 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: a
SmartContextLoadermust preemptively 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
cn.taketoday.context.ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception Load a newApplicationContextbased on the suppliedMergedContextConfiguration, configure the context, and return 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 perform the following actions.- Set the parent
ApplicationContextif appropriate (seeMergedContextConfiguration.getParent()). - Set the active bean definition profiles in the context's
Environment(seeMergedContextConfiguration.getActiveProfiles()). - Add test
PropertySourcesto theEnvironment(seeMergedContextConfiguration.getPropertySourceLocations(),MergedContextConfiguration.getPropertySourceProperties(), andTestPropertySourceUtils). - Invoke
ApplicationContextInitializers(seeMergedContextConfiguration.getContextInitializerClasses()). - Invoke
ContextCustomizers(seeMergedContextConfiguration.getContextCustomizers()). - Register a JVM shutdown hook for the
ApplicationContext. 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 — for example, temporary files.
any exception thrown while attempting to load an
ApplicationContextshould be wrapped in aContextLoadException. Concrete implementations should therefore contain a try-catch block similar to the following.ApplicationContext context = // create context try { // configure and refresh context } catch (Exception ex) { throw new ContextLoadException(context, ex); }- 参数:
mergedConfig- the merged context configuration to use to load the application context- 返回:
- a new application context
- 抛出:
ContextLoadException- if context loading failedException- 另请参阅:
-
processContextConfiguration(ContextConfigurationAttributes)AnnotationConfigUtils.registerAnnotationConfigProcessors(cn.taketoday.beans.factory.support.BeanDefinitionRegistry)ConfigurableApplicationContext.getEnvironment()
- Set the parent
-
processLocations
SmartContextLoaderdoes not support deprecatedContextLoadermethods. CallprocessContextConfiguration(ContextConfigurationAttributes)instead.- 指定者:
processLocations在接口中ContextLoader- 参数:
clazz- the class with which the locations are associated: used to determine how to process the supplied locationslocations- the unmodified locations to use for loading the application context (can benullor empty)- 返回:
- an array of application context resource locations
- 抛出:
UnsupportedOperationException- in this implementation
-
loadContext
SmartContextLoaderdoes not support deprecatedContextLoadermethods.Call
loadContext(MergedContextConfiguration)instead.- 指定者:
loadContext在接口中ContextLoader- 参数:
locations- the resource locations to use to load the application context- 返回:
- a new application context
- 抛出:
UnsupportedOperationException- in this implementationException- if context loading failed
-