Class AbstractRefreshableApplicationContext
- All Implemented Interfaces:
- Closeable,- AutoCloseable,- BeanFactory,- HierarchicalBeanFactory,- ListableBeanFactory,- ApplicationContext,- ApplicationEventPublisher,- ConfigurableApplicationContext,- Lifecycle,- MessageSource,- EnvironmentCapable,- ResourceLoader,- ResourcePatternResolver
- Direct Known Subclasses:
- AbstractRefreshableConfigApplicationContext
ApplicationContext
 implementations which are supposed to support multiple calls to AbstractApplicationContext.refresh(),
 creating a new internal bean factory instance every time.
 Typically (but not necessarily), such a context will be driven by
 a set of config locations to load bean definitions from.
 The only method to be implemented by subclasses is loadBeanDefinitions(org.springframework.beans.factory.support.DefaultListableBeanFactory),
 which gets invoked on each refresh. A concrete implementation is supposed to load
 bean definitions into the given
 DefaultListableBeanFactory,
 typically delegating to one or more specific bean definition readers.
 
Note that there is a similar base class for WebApplicationContexts.
 AbstractRefreshableWebApplicationContext
 provides the same subclassing strategy, but additionally pre-implements
 all context functionality for web environments. There is also a
 pre-defined way to receive config locations for a web context.
 
Concrete standalone subclasses of this base class, reading in a
 specific bean definition format, are ClassPathXmlApplicationContext
 and FileSystemXmlApplicationContext, which both derive from the
 common AbstractXmlApplicationContext base class;
 AnnotationConfigApplicationContext
 supports @Configuration-annotated classes as a source of bean definitions.
- Since:
- 1.1.3
- Author:
- Juergen Hoeller, Chris Beams
- See Also:
- 
Nested Class SummaryNested classes/interfaces inherited from class org.springframework.core.io.DefaultResourceLoaderDefaultResourceLoader.ClassPathContextResource
- 
Field SummaryFields inherited from class org.springframework.context.support.AbstractApplicationContextAPPLICATION_EVENT_MULTICASTER_BEAN_NAME, LIFECYCLE_PROCESSOR_BEAN_NAME, logger, MESSAGE_SOURCE_BEAN_NAMEFields inherited from interface org.springframework.beans.factory.BeanFactoryFACTORY_BEAN_PREFIXFields inherited from interface org.springframework.context.ConfigurableApplicationContextAPPLICATION_STARTUP_BEAN_NAME, CONFIG_LOCATION_DELIMITERS, CONVERSION_SERVICE_BEAN_NAME, ENVIRONMENT_BEAN_NAME, LOAD_TIME_WEAVER_BEAN_NAME, SHUTDOWN_HOOK_THREAD_NAME, SYSTEM_ENVIRONMENT_BEAN_NAME, SYSTEM_PROPERTIES_BEAN_NAMEFields inherited from interface org.springframework.core.io.ResourceLoaderCLASSPATH_URL_PREFIXFields inherited from interface org.springframework.core.io.support.ResourcePatternResolverCLASSPATH_ALL_URL_PREFIX
- 
Constructor SummaryConstructorsConstructorDescriptionCreate a new AbstractRefreshableApplicationContext with no parent.Create a new AbstractRefreshableApplicationContext with the given parent context.
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidOverridden to turn it into a no-op: With AbstractRefreshableApplicationContext,getBeanFactory()serves a strong assertion for an active context anyway.protected voidCancel this context's refresh attempt, resetting theactiveflag after an exception got thrown.protected final voidSubclasses must implement this method to release their internal bean factory.protected DefaultListableBeanFactoryCreate an internal bean factory for this context.protected voidcustomizeBeanFactory(DefaultListableBeanFactory beanFactory) Customize the internal bean factory used by this context.Subclasses must return their internal bean factory here.protected final booleanDetermine whether this context currently holds a bean factory, i.e.protected abstract voidloadBeanDefinitions(DefaultListableBeanFactory beanFactory) Load bean definitions into the given bean factory, typically through delegating to one or more bean definition readers.protected final voidThis implementation performs an actual refresh of this context's underlying bean factory, shutting down the previous bean factory (if any) and initializing a fresh bean factory for the next phase of the context's lifecycle.voidsetAllowBeanDefinitionOverriding(boolean allowBeanDefinitionOverriding) Set whether it should be allowed to override bean definitions by registering a different definition with the same name, automatically replacing the former.voidsetAllowCircularReferences(boolean allowCircularReferences) Set whether to allow circular references between beans - and automatically try to resolve them.Methods inherited from class org.springframework.context.support.AbstractApplicationContextaddApplicationListener, addBeanFactoryPostProcessor, close, containsBean, containsBeanDefinition, containsLocalBean, createEnvironment, destroyBeans, doClose, findAnnotationOnBean, findAnnotationOnBean, finishBeanFactoryInitialization, finishRefresh, getAliases, getApplicationListeners, getApplicationName, getApplicationStartup, getAutowireCapableBeanFactory, getBean, getBean, getBean, getBean, getBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanFactoryPostProcessors, getBeanNamesForAnnotation, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeanProvider, getBeanProvider, getBeanProvider, getBeanProvider, getBeansOfType, getBeansOfType, getBeansWithAnnotation, getDisplayName, getEnvironment, getId, getInternalParentBeanFactory, getInternalParentMessageSource, getMessage, getMessage, getMessage, getParent, getParentBeanFactory, getResourcePatternResolver, getResources, getStartupDate, getType, getType, initApplicationEventMulticaster, initLifecycleProcessor, initMessageSource, initPropertySources, invokeBeanFactoryPostProcessors, isActive, isPrototype, isRunning, isSingleton, isTypeMatch, isTypeMatch, obtainFreshBeanFactory, onClose, onRefresh, postProcessBeanFactory, prepareBeanFactory, prepareRefresh, publishEvent, publishEvent, publishEvent, refresh, registerBeanPostProcessors, registerListeners, registerShutdownHook, resetCommonCaches, setApplicationStartup, setDisplayName, setEnvironment, setId, setParent, start, stop, toStringMethods inherited from class org.springframework.core.io.DefaultResourceLoaderaddProtocolResolver, clearResourceCaches, getClassLoader, getProtocolResolvers, getResource, getResourceByPath, getResourceCache, setClassLoaderMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.context.ConfigurableApplicationContextaddProtocolResolver, setClassLoaderMethods inherited from interface org.springframework.core.io.ResourceLoadergetClassLoader, getResource
- 
Constructor Details- 
AbstractRefreshableApplicationContextpublic AbstractRefreshableApplicationContext()Create a new AbstractRefreshableApplicationContext with no parent.
- 
AbstractRefreshableApplicationContextCreate a new AbstractRefreshableApplicationContext with the given parent context.- Parameters:
- parent- the parent context
 
 
- 
- 
Method Details- 
setAllowBeanDefinitionOverridingpublic void setAllowBeanDefinitionOverriding(boolean allowBeanDefinitionOverriding) Set whether it should be allowed to override bean definitions by registering a different definition with the same name, automatically replacing the former. If not, an exception will be thrown. Default is "true".
- 
setAllowCircularReferencespublic void setAllowCircularReferences(boolean allowCircularReferences) Set whether to allow circular references between beans - and automatically try to resolve them.Default is "true". Turn this off to throw an exception when encountering a circular reference, disallowing them completely. 
- 
refreshBeanFactoryThis implementation performs an actual refresh of this context's underlying bean factory, shutting down the previous bean factory (if any) and initializing a fresh bean factory for the next phase of the context's lifecycle.- Specified by:
- refreshBeanFactoryin class- AbstractApplicationContext
- Throws:
- BeansException- if initialization of the bean factory failed
 
- 
cancelRefreshDescription copied from class:AbstractApplicationContextCancel this context's refresh attempt, resetting theactiveflag after an exception got thrown.- Overrides:
- cancelRefreshin class- AbstractApplicationContext
- Parameters:
- ex- the exception that led to the cancellation
 
- 
closeBeanFactoryprotected final void closeBeanFactory()Description copied from class:AbstractApplicationContextSubclasses must implement this method to release their internal bean factory. This method gets invoked byAbstractApplicationContext.close()after all other shutdown work.Should never throw an exception but rather log shutdown failures. - Specified by:
- closeBeanFactoryin class- AbstractApplicationContext
 
- 
hasBeanFactoryprotected final boolean hasBeanFactory()Determine whether this context currently holds a bean factory, i.e. has been refreshed at least once and not been closed yet.
- 
getBeanFactoryDescription copied from class:AbstractApplicationContextSubclasses must return their internal bean factory here. They should implement the lookup efficiently, so that it can be called repeatedly without a performance penalty.Note: Subclasses should check whether the context is still active before returning the internal bean factory. The internal factory should generally be considered unavailable once the context has been closed. - Specified by:
- getBeanFactoryin interface- ConfigurableApplicationContext
- Specified by:
- getBeanFactoryin class- AbstractApplicationContext
- Returns:
- this application context's internal bean factory (never null)
- See Also:
 
- 
assertBeanFactoryActiveprotected void assertBeanFactoryActive()Overridden to turn it into a no-op: With AbstractRefreshableApplicationContext,getBeanFactory()serves a strong assertion for an active context anyway.- Overrides:
- assertBeanFactoryActivein class- AbstractApplicationContext
 
- 
createBeanFactoryCreate an internal bean factory for this context. Called for eachAbstractApplicationContext.refresh()attempt.The default implementation creates a DefaultListableBeanFactorywith the internal bean factory of this context's parent as parent bean factory. Can be overridden in subclasses, for example to customize DefaultListableBeanFactory's settings.- Returns:
- the bean factory for this context
- See Also:
 
- 
customizeBeanFactoryCustomize the internal bean factory used by this context. Called for eachAbstractApplicationContext.refresh()attempt.The default implementation applies this context's "allowBeanDefinitionOverriding" and "allowCircularReferences" settings, if specified. Can be overridden in subclasses to customize any of DefaultListableBeanFactory's settings.- Parameters:
- beanFactory- the newly created bean factory for this context
- See Also:
 
- 
loadBeanDefinitionsprotected abstract void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException Load bean definitions into the given bean factory, typically through delegating to one or more bean definition readers.- Parameters:
- beanFactory- the bean factory to load bean definitions into
- Throws:
- BeansException- if parsing of the bean definitions failed
- IOException- if loading of bean definition files failed
- See Also:
 
 
-