public abstract class

AbstractRefreshableApplicationContext

extends AbstractApplicationContext
java.lang.Object
   ↳ org.springframework.core.io.DefaultResourceLoader
     ↳ org.springframework.context.support.AbstractApplicationContext
       ↳ org.springframework.context.support.AbstractRefreshableApplicationContext
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

Base class for 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(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.

Summary

[Expand]
Inherited Constants
From class org.springframework.context.support.AbstractApplicationContext
From interface org.springframework.beans.factory.BeanFactory
From interface org.springframework.context.ConfigurableApplicationContext
From interface org.springframework.core.io.ResourceLoader
From interface org.springframework.core.io.support.ResourcePatternResolver
[Expand]
Inherited Fields
From class org.springframework.context.support.AbstractApplicationContext
Public Constructors
AbstractRefreshableApplicationContext()
Create a new AbstractRefreshableApplicationContext with no parent.
AbstractRefreshableApplicationContext(ApplicationContext parent)
Create a new AbstractRefreshableApplicationContext with the given parent context.
Public Methods
final ConfigurableListableBeanFactory getBeanFactory()
Subclasses must return their internal bean factory here.
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.
void setAllowCircularReferences(boolean allowCircularReferences)
Set whether to allow circular references between beans - and automatically try to resolve them.
Protected Methods
void cancelRefresh(BeansException ex)
Cancel this context's refresh attempt, resetting the active flag after an exception got thrown.
final void closeBeanFactory()
Subclasses must implement this method to release their internal bean factory.
DefaultListableBeanFactory createBeanFactory()
Create an internal bean factory for this context.
void customizeBeanFactory(DefaultListableBeanFactory beanFactory)
Customize the internal bean factory used by this context.
final boolean hasBeanFactory()
Determine whether this context currently holds a bean factory, i.e.
abstract void loadBeanDefinitions(DefaultListableBeanFactory beanFactory)
Load bean definitions into the given bean factory, typically through delegating to one or more bean definition readers.
final void 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.
[Expand]
Inherited Methods
From class org.springframework.context.support.AbstractApplicationContext
From class org.springframework.core.io.DefaultResourceLoader
From class java.lang.Object
From interface org.springframework.beans.factory.BeanFactory
From interface org.springframework.beans.factory.DisposableBean
From interface org.springframework.beans.factory.HierarchicalBeanFactory
From interface org.springframework.beans.factory.ListableBeanFactory
From interface org.springframework.context.ApplicationContext
From interface org.springframework.context.ApplicationEventPublisher
From interface org.springframework.context.ConfigurableApplicationContext
From interface org.springframework.context.Lifecycle
From interface org.springframework.context.MessageSource
From interface org.springframework.core.env.EnvironmentCapable
From interface org.springframework.core.io.ResourceLoader
From interface org.springframework.core.io.support.ResourcePatternResolver

Public Constructors

public AbstractRefreshableApplicationContext ()

Create a new AbstractRefreshableApplicationContext with no parent.

public AbstractRefreshableApplicationContext (ApplicationContext parent)

Create a new AbstractRefreshableApplicationContext with the given parent context.

Parameters
parent the parent context

Public Methods

public final ConfigurableListableBeanFactory 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
  • this application context's internal bean factory (never null)

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

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.

Protected Methods

protected void cancelRefresh (BeansException ex)

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

Parameters
ex the exception that led to the cancellation

protected final void 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.

protected DefaultListableBeanFactory createBeanFactory ()

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

The default implementation creates a 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
  • the bean factory for this context

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 the newly created bean factory for this context

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 beanFactory)

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

protected final void 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.