类 AbstractGenericContextLoader
- 所有已实现的接口:
AotContextLoader,ContextLoader,SmartContextLoader
AbstractContextLoader that loads a
GenericApplicationContext.
- If instances of concrete subclasses are invoked via the
ContextLoaderSPI, the context will be loaded from the locations provided toloadContext(String...). - If instances of concrete subclasses are invoked via the
SmartContextLoaderSPI, the context will be loaded from theMergedContextConfigurationprovided toloadContext(MergedContextConfiguration). In such cases, aSmartContextLoaderwill decide whether to load the context from locations or annotated classes.
Concrete subclasses must provide an appropriate implementation of
createBeanDefinitionReader(),
potentially overriding loadBeanDefinitions()
as well.
- 从以下版本开始:
- 4.0
- 作者:
- Sam Brannen, Juergen Hoeller, Phillip Webb, Harry Yang
- 另请参阅:
-
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明protected abstract cn.taketoday.beans.factory.support.BeanDefinitionReadercreateBeanDefinitionReader(cn.taketoday.context.support.GenericApplicationContext context) Factory method for creating a newBeanDefinitionReaderfor loading bean definitions into the suppliedcontext.protected cn.taketoday.context.support.GenericApplicationContextFactory method for creating theGenericApplicationContextused by thisContextLoader.protected voidcustomizeBeanFactory(cn.taketoday.beans.factory.support.StandardBeanFactory beanFactory) Customize the internal bean factory of the ApplicationContext created by thisContextLoader.protected voidcustomizeContext(cn.taketoday.context.support.GenericApplicationContext context) Customize theGenericApplicationContextcreated by thisContextLoaderafter bean definitions have been loaded into the context but before the context is refreshed.protected voidloadBeanDefinitions(cn.taketoday.context.support.GenericApplicationContext context, MergedContextConfiguration mergedConfig) Load bean definitions into the suppliedcontextfrom the locations or classes in the suppliedMergedContextConfiguration.final cn.taketoday.context.ApplicationContextloadContext(MergedContextConfiguration mergedConfig) Load aGenericApplicationContextfor the suppliedMergedContextConfiguration.private cn.taketoday.context.support.GenericApplicationContextloadContext(MergedContextConfiguration mergedConfig, boolean forAotProcessing) Load aGenericApplicationContextfor the suppliedMergedContextConfiguration.final cn.taketoday.context.ConfigurableApplicationContextloadContext(String... locations) Load a Infra ApplicationContext from the suppliedlocations.final cn.taketoday.context.support.GenericApplicationContextloadContextForAotProcessing(MergedContextConfiguration mergedConfig) Load aGenericApplicationContextfor AOT build-time processing based on the suppliedMergedContextConfiguration.final cn.taketoday.context.support.GenericApplicationContextloadContextForAotRuntime(MergedContextConfiguration mergedConfig, cn.taketoday.context.ApplicationContextInitializer initializer) Load aGenericApplicationContextfor AOT run-time execution based on the suppliedMergedContextConfigurationandApplicationContextInitializer.protected voidprepareContext(cn.taketoday.context.support.GenericApplicationContext context) Prepare theGenericApplicationContextcreated by thisContextLoader.protected voidvalidateMergedContextConfiguration(MergedContextConfiguration mergedConfig) Validate the suppliedMergedContextConfigurationwith 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
-
字段详细资料
-
log
protected static final cn.taketoday.logging.Logger log
-
-
构造器详细资料
-
AbstractGenericContextLoader
public AbstractGenericContextLoader()
-
-
方法详细资料
-
loadContext
public final cn.taketoday.context.ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception Load aGenericApplicationContextfor the suppliedMergedContextConfiguration.Implementation details:
- Calls
validateMergedContextConfiguration(MergedContextConfiguration)to allow subclasses to validate the supplied configuration before proceeding. - Calls
createContext()to create aGenericApplicationContextinstance. - If the supplied
MergedContextConfigurationreferences a parent configuration, the correspondingApplicationContextwill be retrieved and set as the parent for the context created by this method. - Calls
prepareContext(GenericApplicationContext)for backwards compatibility with theContextLoaderSPI. - Calls
AbstractContextLoader.prepareContext(ConfigurableApplicationContext, MergedContextConfiguration)to allow for customizing the context before bean definitions are loaded. - Calls
customizeBeanFactory(StandardBeanFactory)to allow for customizing the context'sDefaultListableBeanFactory. - Delegates to
loadBeanDefinitions(GenericApplicationContext, MergedContextConfiguration)to populate the context from the locations or classes in the suppliedMergedContextConfiguration. - Delegates to
AnnotationConfigUtilsforregisteringannotation configuration processors. - Calls
customizeContext(GenericApplicationContext)to allow for customizing the context before it is refreshed. - Calls
AbstractContextLoader.customizeContext(ConfigurableApplicationContext, MergedContextConfiguration)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 application context
- 抛出:
ContextLoadException- if context loading failedException- 另请参阅:
- Calls
-
loadContextForAotProcessing
public final cn.taketoday.context.support.GenericApplicationContext loadContextForAotProcessing(MergedContextConfiguration mergedConfig) throws Exception Load aGenericApplicationContextfor 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 application context
- 抛出:
Exception- if context loading failed- 另请参阅:
-
loadContextForAotRuntime
public final cn.taketoday.context.support.GenericApplicationContext loadContextForAotRuntime(MergedContextConfiguration mergedConfig, cn.taketoday.context.ApplicationContextInitializer initializer) throws Exception Load aGenericApplicationContextfor 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 application context
- 抛出:
Exception- if context loading failed- 另请参阅:
-
loadContext
private cn.taketoday.context.support.GenericApplicationContext loadContext(MergedContextConfiguration mergedConfig, boolean forAotProcessing) throws Exception Load aGenericApplicationContextfor 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 application context
- 抛出:
Exception
-
validateMergedContextConfiguration
Validate the suppliedMergedContextConfigurationwith 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
-
loadContext
public final cn.taketoday.context.ConfigurableApplicationContext loadContext(String... locations) throws Exception Load a Infra ApplicationContext from the suppliedlocations.Implementation details:
- Calls
createContext()to create aGenericApplicationContextinstance. - Calls
prepareContext(GenericApplicationContext)to allow for customizing the context before bean definitions are loaded. - Calls
customizeBeanFactory(StandardBeanFactory)to allow for customizing the context'sDefaultListableBeanFactory. - Delegates to
createBeanDefinitionReader(GenericApplicationContext)to create aBeanDefinitionReaderwhich is then used to populate the context from the specified locations. - Delegates to
AnnotationConfigUtilsforregisteringannotation configuration processors. - Calls
customizeContext(GenericApplicationContext)to allow for customizing the context before it is refreshed. Refreshesthe context and registers a JVM shutdown hook for it.
Note: this method does not provide a means to set active bean definition profiles for the loaded context. See
loadContext(MergedContextConfiguration)andAbstractContextLoader.prepareContext(ConfigurableApplicationContext, MergedContextConfiguration)for an alternative.- 指定者:
loadContext在接口中ContextLoader- 指定者:
loadContext在接口中SmartContextLoader- 参数:
locations- the resource locations to use to load the application context- 返回:
- a new application context
- 抛出:
Exception- if context loading failed- 另请参阅:
-
ContextLoader.loadContext(java.lang.String...)GenericApplicationContextloadContext(MergedContextConfiguration)
- Calls
-
createContext
protected cn.taketoday.context.support.GenericApplicationContext createContext()Factory method for creating theGenericApplicationContextused by thisContextLoader.The default implementation creates a
GenericApplicationContextusing the default constructor. This method may be overridden — for example, to use a custom context subclass or to create aGenericApplicationContextwith a customStandardBeanFactoryimplementation.- 返回:
- a newly instantiated
GenericApplicationContext
-
prepareContext
protected void prepareContext(cn.taketoday.context.support.GenericApplicationContext context) Prepare theGenericApplicationContextcreated by thisContextLoader. Called before bean definitions are read.The default implementation is empty. Can be overridden in subclasses to customize
GenericApplicationContext's standard settings.- 参数:
context- the context that should be prepared- 另请参阅:
-
loadContext(MergedContextConfiguration)GenericApplicationContext.setAllowBeanDefinitionOverriding(boolean)GenericApplicationContext.setResourceLoader(cn.taketoday.core.io.ResourceLoader)AbstractApplicationContext.setId(java.lang.String)AbstractContextLoader.prepareContext(ConfigurableApplicationContext, MergedContextConfiguration)
-
customizeBeanFactory
protected void customizeBeanFactory(cn.taketoday.beans.factory.support.StandardBeanFactory beanFactory) Customize the internal bean factory of the ApplicationContext created by thisContextLoader.The default implementation is empty but can be overridden in subclasses to customize
DefaultListableBeanFactory's standard settings.- 参数:
beanFactory- the bean factory created by thisContextLoader- 另请参阅:
-
loadContext(MergedContextConfiguration)StandardBeanFactory.setAllowBeanDefinitionOverriding(boolean)StandardBeanFactory.setAllowEagerClassLoading(boolean)AbstractAutowireCapableBeanFactory.setAllowCircularReferences(boolean)AbstractAutowireCapableBeanFactory.setAllowRawInjectionDespiteWrapping(boolean)
-
loadBeanDefinitions
protected void loadBeanDefinitions(cn.taketoday.context.support.GenericApplicationContext context, MergedContextConfiguration mergedConfig) Load bean definitions into the suppliedcontextfrom the locations or classes in the suppliedMergedContextConfiguration.The default implementation delegates to the
BeanDefinitionReaderreturned bycreateBeanDefinitionReader(GenericApplicationContext)toloadthe bean definitions.Subclasses must provide an appropriate implementation of
createBeanDefinitionReader(GenericApplicationContext). Alternatively subclasses may provide a no-op implementation ofcreateBeanDefinitionReader()and override this method to provide a custom strategy for loading or registering bean definitions.- 参数:
context- the context into which the bean definitions should be loadedmergedConfig- the merged context configuration- 另请参阅:
-
createBeanDefinitionReader
protected abstract cn.taketoday.beans.factory.support.BeanDefinitionReader createBeanDefinitionReader(cn.taketoday.context.support.GenericApplicationContext context) Factory method for creating a newBeanDefinitionReaderfor loading bean definitions into the suppliedcontext.- 参数:
context- the context for which theBeanDefinitionReadershould be created- 返回:
- a
BeanDefinitionReaderfor the supplied context - 另请参阅:
-
customizeContext
protected void customizeContext(cn.taketoday.context.support.GenericApplicationContext context) Customize theGenericApplicationContextcreated by thisContextLoaderafter bean definitions have been loaded into the context but before the context is refreshed.The default implementation is empty but can be overridden in subclasses to customize the application context.
- 参数:
context- the newly created application context- 另请参阅:
-