Top Description Fields Constructors Methods
org.springframework.context.support

public abstract Class AbstractRefreshableApplicationContext

extends AbstractApplicationContext
Class Inheritance
Known Direct Subclasses
org.springframework.context.support.AbstractRefreshableConfigApplicationContext
Imports
java.io.IOException, org.springframework.beans.BeansException, org.springframework.beans.factory.config.ConfigurableListableBeanFactory, org.springframework.beans.factory.support.DefaultListableBeanFactory, org.springframework.context.ApplicationContext, .ApplicationContextException, org.springframework.lang.Nullable

Base class for org.springframework.context.ApplicationContext implementations which are supposed to support multiple calls to 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, which gets invoked on each refresh. A concrete implementation is supposed to load bean definitions into the given org.springframework.beans.factory.support.DefaultListableBeanFactory, typically delegating to one or more specific bean definition readers.

Note that there is a similar base class for WebApplicationContexts. org.springframework.web.context.support.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; org.springframework.context.annotation.AnnotationConfigApplicationContext supports @Configuration-annotated classes as a source of bean definitions.

Authors
Juergen Hoeller, Chris Beams
Since
1.1.3
See Also
loadBeanDefinitions, org.springframework.beans.factory.support.DefaultListableBeanFactory, org.springframework.web.context.support.AbstractRefreshableWebApplicationContext, AbstractXmlApplicationContext, ClassPathXmlApplicationContext, FileSystemXmlApplicationContext, org.springframework.context.annotation.AnnotationConfigApplicationContext

Field Summary

Modifier and TypeField and Description
private Boolean
private Boolean
private volatile DefaultListableBeanFactory
beanFactory

Bean factory for this context.

Inherited from org.springframework.context.support.AbstractApplicationContext:
APPLICATION_EVENT_MULTICASTER_BEAN_NAMELIFECYCLE_PROCESSOR_BEAN_NAMEloggerMESSAGE_SOURCE_BEAN_NAME

Constructor Summary

AccessConstructor and Description
public
AbstractRefreshableApplicationContext()

Create a new AbstractRefreshableApplicationContext with no parent.

public
AbstractRefreshableApplicationContext(ApplicationContext
the parent context
parent
)

Create a new AbstractRefreshableApplicationContext with the given parent context.

Method Summary

Modifier and TypeMethod and Description
protected void
assertBeanFactoryActive()

Overrides org.springframework.context.support.AbstractApplicationContext.assertBeanFactoryActive.

Overridden to turn it into a no-op: With AbstractRefreshableApplicationContext, getBeanFactory() serves a strong assertion for an active context anyway.
protected void
cancelRefresh(Throwable
the exception that led to the cancellation
ex
)

Overrides org.springframework.context.support.AbstractApplicationContext.cancelRefresh.

Cancel this context's refresh attempt, resetting the active flag after an exception got thrown.
protected final void
closeBeanFactory()

Implements abstract org.springframework.context.support.AbstractApplicationContext.closeBeanFactory.

Subclasses must implement this method to release their internal bean factory.
protected DefaultListableBeanFactory

Returns:

the bean factory for this context
createBeanFactory
()

Create an internal bean factory for this context.

protected void
customizeBeanFactory(DefaultListableBeanFactory
the newly created bean factory for this context
beanFactory
)

Customize the internal bean factory used by this context.

public final ConfigurableListableBeanFactory
protected 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.

protected abstract void
loadBeanDefinitions(DefaultListableBeanFactory
the bean factory to load bean definitions into
beanFactory
)

Load bean definitions into the given bean factory, typically through delegating to one or more bean definition readers.

protected final void
refreshBeanFactory()

Implements abstract org.springframework.context.support.AbstractApplicationContext.refreshBeanFactory.

This 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.
public 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.

public void
setAllowCircularReferences(boolean allowCircularReferences)

Set whether to allow circular references between beans - and automatically try to resolve them.

Inherited from org.springframework.context.support.AbstractApplicationContext:
addApplicationListeneraddBeanFactoryPostProcessorclosecontainsBeancontainsBeanDefinitioncontainsLocalBeancreateEnvironmentdestroyBeansdoClosefindAllAnnotationsOnBeanfindAnnotationOnBeanfindAnnotationOnBeanfinishBeanFactoryInitializationfinishRefreshgetAliasesgetApplicationEventMulticastergetApplicationListenersgetApplicationNamegetApplicationStartupgetAutowireCapableBeanFactorygetBeangetBeangetBeangetBeangetBeangetBeanDefinitionCountgetBeanDefinitionNamesgetBeanFactoryPostProcessorsgetBeanNamesForAnnotationgetBeanNamesForTypegetBeanNamesForTypegetBeanNamesForTypegetBeanNamesForTypegetBeanProvidergetBeanProvidergetBeanProvidergetBeanProvidergetBeansOfTypegetBeansOfTypegetBeansWithAnnotationgetDisplayNamegetEnvironmentgetIdgetInternalParentBeanFactorygetInternalParentMessageSourcegetLifecycleProcessorgetMessagegetMessagegetMessagegetParentgetParentBeanFactorygetResourcePatternResolvergetResourcesgetStartupDategetTypegetTypeinitApplicationEventMulticasterinitLifecycleProcessorinitMessageSourceinitPropertySourcesinvokeBeanFactoryPostProcessorsisActiveisPrototypeisRunningisSingletonisTypeMatchisTypeMatchobtainFreshBeanFactoryonCloseonRefreshpostProcessBeanFactoryprepareBeanFactoryprepareRefreshpublishEventpublishEventpublishEventrefreshregisterBeanPostProcessorsregisterListenersregisterShutdownHookremoveApplicationListenerresetCommonCachessetApplicationStartupsetDisplayNamesetEnvironmentsetIdsetParentstartstoptoString

Field Detail

allowBeanDefinitionOverridingback to summary
private Boolean allowBeanDefinitionOverriding
Annotations
@Nullable
allowCircularReferencesback to summary
private Boolean allowCircularReferences
Annotations
@Nullable
beanFactoryback to summary
private volatile DefaultListableBeanFactory beanFactory

Bean factory for this context.

Annotations
@Nullable

Constructor Detail

AbstractRefreshableApplicationContextback to summary
public AbstractRefreshableApplicationContext()

Create a new AbstractRefreshableApplicationContext with no parent.

AbstractRefreshableApplicationContextback to summary
public AbstractRefreshableApplicationContext(ApplicationContext parent)

Create a new AbstractRefreshableApplicationContext with the given parent context.

Parameters
parent:ApplicationContext

the parent context

Method Detail

assertBeanFactoryActiveback to summary
protected void assertBeanFactoryActive()

Overrides org.springframework.context.support.AbstractApplicationContext.assertBeanFactoryActive.

Overridden to turn it into a no-op: With AbstractRefreshableApplicationContext, getBeanFactory() serves a strong assertion for an active context anyway.

Annotations
@Override
cancelRefreshback to summary
protected void cancelRefresh(Throwable ex)

Overrides org.springframework.context.support.AbstractApplicationContext.cancelRefresh.

Doc from org.springframework.context.support.AbstractApplicationContext.cancelRefresh.

Cancel this context's refresh attempt, resetting the active flag after an exception got thrown.

Parameters
ex:Throwable

the exception that led to the cancellation

Annotations
@Override
closeBeanFactoryback to summary
protected final void closeBeanFactory()

Implements abstract org.springframework.context.support.AbstractApplicationContext.closeBeanFactory.

Doc from org.springframework.context.support.AbstractApplicationContext.closeBeanFactory.

Subclasses must implement this method to release their internal bean factory. This method gets invoked by close() after all other shutdown work.

Should never throw an exception but rather log shutdown failures.

Annotations
@Override
createBeanFactoryback to summary
protected DefaultListableBeanFactory createBeanFactory()

Create an internal bean factory for this context. Called for each refresh() attempt.

The default implementation creates a org.springframework.beans.factory.support.DefaultListableBeanFactory with 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:DefaultListableBeanFactory

the bean factory for this context

See Also
org.springframework.beans.factory.support.DefaultListableBeanFactory#setAllowBeanDefinitionOverriding, org.springframework.beans.factory.support.DefaultListableBeanFactory#setAllowEagerClassLoading, org.springframework.beans.factory.support.DefaultListableBeanFactory#setAllowCircularReferences, org.springframework.beans.factory.support.DefaultListableBeanFactory#setAllowRawInjectionDespiteWrapping
customizeBeanFactoryback to summary
protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory)

Customize the internal bean factory used by this context. Called for each 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:DefaultListableBeanFactory

the newly created bean factory for this context

See Also
DefaultListableBeanFactory#setAllowBeanDefinitionOverriding, DefaultListableBeanFactory#setAllowCircularReferences, DefaultListableBeanFactory#setAllowRawInjectionDespiteWrapping, DefaultListableBeanFactory#setAllowEagerClassLoading
getBeanFactoryback to summary
public final ConfigurableListableBeanFactory getBeanFactory()

Implements abstract org.springframework.context.support.AbstractApplicationContext.getBeanFactory.

Implements org.springframework.context.ConfigurableApplicationContext.getBeanFactory.

Doc from org.springframework.context.support.AbstractApplicationContext.getBeanFactory.

Subclasses 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.

Returns:ConfigurableListableBeanFactory

this application context's internal bean factory (never null)

Annotations
@Override
hasBeanFactoryback to summary
protected 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.

loadBeanDefinitionsback to summary
protected 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:DefaultListableBeanFactory

the bean factory to load bean definitions into

Exceptions
BeansException:
if parsing of the bean definitions failed
IOException:
if loading of bean definition files failed
See Also
org.springframework.beans.factory.support.PropertiesBeanDefinitionReader, org.springframework.beans.factory.xml.XmlBeanDefinitionReader
refreshBeanFactoryback to summary
protected final void refreshBeanFactory() throws BeansException

Implements abstract org.springframework.context.support.AbstractApplicationContext.refreshBeanFactory.

This 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.

Annotations
@Override
Exceptions
BeansException:

Doc from org.springframework.context.support.AbstractApplicationContext.refreshBeanFactory.

if initialization of the bean factory failed

setAllowBeanDefinitionOverridingback to summary
public 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".

See Also
org.springframework.beans.factory.support.DefaultListableBeanFactory#setAllowBeanDefinitionOverriding
setAllowCircularReferencesback to summary
public 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.

See Also
org.springframework.beans.factory.support.DefaultListableBeanFactory#setAllowCircularReferences