类 AbstractGenericWebContextLoader
- 所有已实现的接口:
AotContextLoader,ContextLoader,SmartContextLoader
AbstractContextLoader that loads a
GenericWebApplicationContext.
If instances of concrete subclasses are invoked via the
SmartContextLoader
SPI, the context will be loaded from the MergedContextConfiguration
provided to loadContext(MergedContextConfiguration). In such cases, a
SmartContextLoader will decide whether to load the context from
locations or annotated classes. Note that
AbstractGenericWebContextLoader does not support the
loadContext(String... locations) method from the legacy
ContextLoader SPI.
Concrete subclasses must provide an appropriate implementation of
loadBeanDefinitions(cn.taketoday.web.servlet.support.GenericWebApplicationContext, cn.taketoday.test.context.web.WebMergedContextConfiguration).
- 从以下版本开始:
- 4.0
- 作者:
- Sam Brannen, Phillip Webb, Harry Yang
- 另请参阅:
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected voidconfigureWebResources(cn.taketoday.web.servlet.support.GenericWebApplicationContext context, WebMergedContextConfiguration webMergedConfig) Configures web resources for the supplied web application context (WAC).protected cn.taketoday.web.servlet.support.GenericWebApplicationContextFactory method for creating theGenericWebApplicationContextused by thisContextLoader.protected voidcustomizeBeanFactory(cn.taketoday.beans.factory.support.StandardBeanFactory beanFactory, WebMergedContextConfiguration webMergedConfig) Customize the internal bean factory of theWebApplicationContextcreated by this context loader.protected voidcustomizeContext(cn.taketoday.web.servlet.support.GenericWebApplicationContext context, WebMergedContextConfiguration webMergedConfig) Customize theGenericWebApplicationContextcreated by this context loader after bean definitions have been loaded into the context but before the context is refreshed.protected abstract voidloadBeanDefinitions(cn.taketoday.web.servlet.support.GenericWebApplicationContext context, WebMergedContextConfiguration webMergedConfig) Load bean definitions into the suppliedcontextfrom the locations or classes in the suppliedWebMergedContextConfiguration.final cn.taketoday.context.ApplicationContextloadContext(MergedContextConfiguration mergedConfig) Load aGenericWebApplicationContextfor the suppliedMergedContextConfiguration.private final cn.taketoday.web.servlet.support.GenericWebApplicationContextloadContext(MergedContextConfiguration mergedConfig, boolean forAotProcessing) Load aGenericWebApplicationContextfor the suppliedMergedContextConfiguration.final cn.taketoday.context.ApplicationContextloadContext(String... locations) AbstractGenericWebContextLoadershould be used as aSmartContextLoader, not as a legacyContextLoader.final cn.taketoday.web.servlet.support.GenericWebApplicationContextloadContextForAotProcessing(MergedContextConfiguration mergedConfig) Load aGenericWebApplicationContextfor AOT build-time processing based on the suppliedMergedContextConfiguration.final cn.taketoday.web.servlet.support.GenericWebApplicationContextloadContextForAotRuntime(MergedContextConfiguration mergedConfig, cn.taketoday.context.ApplicationContextInitializer initializer) Load aGenericWebApplicationContextfor AOT run-time execution based on the suppliedMergedContextConfigurationandApplicationContextInitializer.protected voidValidate the suppliedWebMergedContextConfigurationwith respect to what this context loader supports.从类继承的方法 cn.taketoday.test.context.support.AbstractContextLoader
customizeContext, generateDefaultLocations, getResourceSuffix, getResourceSuffixes, isGenerateDefaultLocations, modifyLocations, prepareContext, processContextConfiguration, processLocations从类继承的方法 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait从接口继承的方法 cn.taketoday.test.context.SmartContextLoader
processContextConfiguration, processLocations
-
字段详细资料
-
logger
protected static final cn.taketoday.logging.Logger logger
-
-
构造器详细资料
-
AbstractGenericWebContextLoader
public AbstractGenericWebContextLoader()
-
-
方法详细资料
-
loadContext
public final cn.taketoday.context.ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception Load aGenericWebApplicationContextfor the suppliedMergedContextConfiguration.Implementation details:
- Calls
validateMergedContextConfiguration(WebMergedContextConfiguration)to allow subclasses to validate the supplied configuration before proceeding. - Creates a
GenericWebApplicationContextinstance. - If the supplied
MergedContextConfigurationreferences a parent configuration, the correspondingApplicationContextwill be retrieved and set as the parent for the context created by this method. - Delegates to
configureWebResources(cn.taketoday.web.servlet.support.GenericWebApplicationContext, cn.taketoday.test.context.web.WebMergedContextConfiguration)to create theMockServletContextand set it in theWebApplicationContext. - Calls
AbstractContextLoader.prepareContext(cn.taketoday.context.ConfigurableApplicationContext, cn.taketoday.test.context.MergedContextConfiguration)to allow for customizing the context before bean definitions are loaded. - Calls
customizeBeanFactory(cn.taketoday.beans.factory.support.StandardBeanFactory, cn.taketoday.test.context.web.WebMergedContextConfiguration)to allow for customizing the context'sStandardBeanFactory. - Delegates to
loadBeanDefinitions(cn.taketoday.web.servlet.support.GenericWebApplicationContext, cn.taketoday.test.context.web.WebMergedContextConfiguration)to populate the context from the locations or classes in the suppliedMergedContextConfiguration. - Delegates to
AnnotationConfigUtilsfor registering annotation configuration processors. - Calls
customizeContext(cn.taketoday.web.servlet.support.GenericWebApplicationContext, cn.taketoday.test.context.web.WebMergedContextConfiguration)to allow for customizing the context before it is refreshed. Refreshesthe context and registers a JVM shutdown hook for it.
- 指定者:
loadContext在接口中SmartContextLoader- 参数:
mergedConfig- the merged context configuration to use to load the application context- 返回:
- a new web application context
- 抛出:
ContextLoadException- if context loading failedException- 另请参阅:
- Calls
-
loadContextForAotProcessing
public final cn.taketoday.web.servlet.support.GenericWebApplicationContext loadContextForAotProcessing(MergedContextConfiguration mergedConfig) throws Exception Load aGenericWebApplicationContextfor AOT build-time processing based on the suppliedMergedContextConfiguration.In contrast to
loadContext(MergedContextConfiguration), this method does not refresh theApplicationContextor register a JVM shutdown hook for it. Otherwise, this method implements behavior identical toloadContext(MergedContextConfiguration).- 指定者:
loadContextForAotProcessing在接口中AotContextLoader- 参数:
mergedConfig- the merged context configuration to use to load the application context- 返回:
- a new web application context
- 抛出:
Exception- if context loading failed- 另请参阅:
-
loadContextForAotRuntime
public final cn.taketoday.web.servlet.support.GenericWebApplicationContext loadContextForAotRuntime(MergedContextConfiguration mergedConfig, cn.taketoday.context.ApplicationContextInitializer initializer) throws Exception Load aGenericWebApplicationContextfor AOT run-time execution based on the suppliedMergedContextConfigurationandApplicationContextInitializer.- 指定者:
loadContextForAotRuntime在接口中AotContextLoader- 参数:
mergedConfig- the merged context configuration to use to load the application contextinitializer- theApplicationContextInitializerthat should be applied to the context in order to recreate bean definitions- 返回:
- a new web application context
- 抛出:
Exception- if context loading failed- 另请参阅:
-
loadContext
private final cn.taketoday.web.servlet.support.GenericWebApplicationContext loadContext(MergedContextConfiguration mergedConfig, boolean forAotProcessing) throws Exception Load aGenericWebApplicationContextfor the suppliedMergedContextConfiguration.- 参数:
mergedConfig- the merged context configuration to use to load the application contextforAotProcessing-trueif the context is being loaded for AOT processing, meaning not to refresh theApplicationContextor register a JVM shutdown hook for it- 返回:
- a new web application context
- 抛出:
Exception- 另请参阅:
-
validateMergedContextConfiguration
Validate the suppliedWebMergedContextConfigurationwith respect to what this context loader supports.The default implementation is a no-op but can be overridden by subclasses as appropriate.
- 参数:
mergedConfig- the merged configuration to validate- 抛出:
IllegalStateException- if the supplied configuration is not valid for this context loader
-
createContext
protected cn.taketoday.web.servlet.support.GenericWebApplicationContext createContext()Factory method for creating theGenericWebApplicationContextused by thisContextLoader.The default implementation creates a
GenericWebApplicationContextusing the default constructor. This method may be overridden — for example, to use a custom context subclass or to create aGenericWebApplicationContextwith a customStandardBeanFactoryimplementation.- 返回:
- a newly instantiated
GenericWebApplicationContext
-
configureWebResources
protected void configureWebResources(cn.taketoday.web.servlet.support.GenericWebApplicationContext context, WebMergedContextConfiguration webMergedConfig) Configures web resources for the supplied web application context (WAC).Implementation Details
If the supplied WAC has no parent or its parent is not a WAC, the supplied WAC will be configured as the Root WAC (see "Root WAC Configuration" below).
Otherwise the context hierarchy of the supplied WAC will be traversed to find the top-most WAC (i.e., the root); and the
ServletContextof the Root WAC will be set as theServletContextfor the supplied WAC.Root WAC Configuration
- The resource base path is retrieved from the supplied
WebMergedContextConfiguration. - A
ResourceLoaderis instantiated for theMockServletContext: if the resource base path is prefixed with "classpath:", aDefaultResourceLoaderwill be used; otherwise, aFileSystemResourceLoaderwill be used. - A
MockServletContextwill be created using the resource base path and resource loader. - The supplied
GenericWebApplicationContextis then stored in theMockServletContextunder theWebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTEkey. - Finally, the
MockServletContextis set in theWebApplicationContext.
- 参数:
context- the web application context for which to configure the web resourceswebMergedConfig- the merged context configuration to use to load the web application context
- The resource base path is retrieved from the supplied
-
customizeBeanFactory
protected void customizeBeanFactory(cn.taketoday.beans.factory.support.StandardBeanFactory beanFactory, WebMergedContextConfiguration webMergedConfig) Customize the internal bean factory of theWebApplicationContextcreated by this context loader.The default implementation is empty but can be overridden in subclasses to customize
StandardBeanFactory's standard settings.- 参数:
beanFactory- the bean factory created by this context loaderwebMergedConfig- the merged context configuration to use to load the web application context- 另请参阅:
-
loadContext(MergedContextConfiguration)StandardBeanFactory.setAllowBeanDefinitionOverriding(boolean)StandardBeanFactory.setAllowEagerClassLoading(boolean)AbstractAutowireCapableBeanFactory.setAllowCircularReferences(boolean)AbstractAutowireCapableBeanFactory.setAllowRawInjectionDespiteWrapping(boolean)
-
loadBeanDefinitions
protected abstract void loadBeanDefinitions(cn.taketoday.web.servlet.support.GenericWebApplicationContext context, WebMergedContextConfiguration webMergedConfig) Load bean definitions into the suppliedcontextfrom the locations or classes in the suppliedWebMergedContextConfiguration.Concrete subclasses must provide an appropriate implementation.
- 参数:
context- the context into which the bean definitions should be loadedwebMergedConfig- the merged context configuration to use to load the web application context- 另请参阅:
-
customizeContext
protected void customizeContext(cn.taketoday.web.servlet.support.GenericWebApplicationContext context, WebMergedContextConfiguration webMergedConfig) Customize theGenericWebApplicationContextcreated by this context loader after bean definitions have been loaded into the context but before the context is refreshed.The default implementation simply delegates to
AbstractContextLoader.customizeContext(ConfigurableApplicationContext, MergedContextConfiguration).- 参数:
context- the newly created web application contextwebMergedConfig- the merged context configuration to use to load the web application context- 另请参阅:
-
loadContext
public final cn.taketoday.context.ApplicationContext loadContext(String... locations) throws Exception AbstractGenericWebContextLoadershould be used as aSmartContextLoader, not as a legacyContextLoader. Consequently, this method is not supported.- 指定者:
loadContext在接口中ContextLoader- 指定者:
loadContext在接口中SmartContextLoader- 参数:
locations- the resource locations to use to load the application context- 返回:
- a new application context
- 抛出:
UnsupportedOperationException- in this implementationException- if context loading failed- 另请参阅:
-