org.springframework.context.support
Class AbstractRefreshableApplicationContext

java.lang.Object
  extended byorg.springframework.core.io.DefaultResourceLoader
      extended byorg.springframework.context.support.AbstractApplicationContext
          extended byorg.springframework.context.support.AbstractRefreshableApplicationContext
All Implemented Interfaces:
ApplicationContext, ApplicationEventPublisher, BeanFactory, ConfigurableApplicationContext, HierarchicalBeanFactory, ListableBeanFactory, MessageSource, ResourceLoader, ResourcePatternResolver
Direct Known Subclasses:
AbstractRefreshableWebApplicationContext, AbstractXmlApplicationContext

public abstract class AbstractRefreshableApplicationContext
extends AbstractApplicationContext

Base class for ApplicationContext implementations that are supposed to support multiple refreshs, 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 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.

Since:
1.1.3
Author:
Juergen Hoeller
See Also:
loadBeanDefinitions(org.springframework.beans.factory.support.DefaultListableBeanFactory), DefaultListableBeanFactory, PropertiesBeanDefinitionReader, XmlBeanDefinitionReader, AbstractRefreshableWebApplicationContext, AbstractXmlApplicationContext, ClassPathXmlApplicationContext, FileSystemXmlApplicationContext

Field Summary
 
Fields inherited from class org.springframework.context.support.AbstractApplicationContext
APPLICATION_EVENT_MULTICASTER_BEAN_NAME, logger, MESSAGE_SOURCE_BEAN_NAME
 
Fields inherited from interface org.springframework.beans.factory.BeanFactory
FACTORY_BEAN_PREFIX
 
Fields inherited from interface org.springframework.core.io.support.ResourcePatternResolver
CLASSPATH_URL_PREFIX
 
Constructor Summary
AbstractRefreshableApplicationContext()
          Create a new AbstractRefreshableApplicationContext with no parent.
AbstractRefreshableApplicationContext(ApplicationContext parent)
          Create a new AbstractRefreshableApplicationContext with the given parent context.
 
Method Summary
protected  DefaultListableBeanFactory createBeanFactory()
          Create the bean factory for this context.
 ConfigurableListableBeanFactory getBeanFactory()
          Subclasses must return their internal bean factory here.
protected abstract  void loadBeanDefinitions(DefaultListableBeanFactory beanFactory)
          Load bean definitions into the given bean factory, typically through delegating to one or more bean definition readers.
protected  void refreshBeanFactory()
          Subclasses must implement this method to perform the actual configuration load.
 
Methods inherited from class org.springframework.context.support.AbstractApplicationContext
addBeanFactoryPostProcessor, addListener, close, containsBean, containsBeanDefinition, getAliases, getBean, getBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanDefinitionNames, getBeanFactoryPostProcessors, getBeanNamesForType, getBeansOfType, getBeansOfType, getDisplayName, getInternalParentBeanFactory, getInternalParentMessageSource, getMessage, getMessage, getMessage, getParent, getParentBeanFactory, getResourcePatternResolver, getResources, getStartupDate, getType, isSingleton, onRefresh, postProcessBeanFactory, publishEvent, refresh, setDisplayName, setParent, toString
 
Methods inherited from class org.springframework.core.io.DefaultResourceLoader
getClassLoader, getResource, getResourceByPath
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.springframework.core.io.ResourceLoader
getResource
 

Constructor Detail

AbstractRefreshableApplicationContext

public AbstractRefreshableApplicationContext()
Create a new AbstractRefreshableApplicationContext with no parent.


AbstractRefreshableApplicationContext

public AbstractRefreshableApplicationContext(ApplicationContext parent)
Create a new AbstractRefreshableApplicationContext with the given parent context.

Parameters:
parent - the parent context
Method Detail

refreshBeanFactory

protected final void refreshBeanFactory()
                                 throws BeansException
Description copied from class: AbstractApplicationContext
Subclasses must implement this method to perform the actual configuration load. The method is invoked by refresh before any other initialization work.

A subclass will either create a new bean factory and hold a reference to it, or return a single bean factory instance that it holds. In the latter case, it will usually throw an IllegalStateException if refreshing the context more than once.

Specified by:
refreshBeanFactory in class AbstractApplicationContext
Throws:
BeansException - if initialization of the bean factory failed
See Also:
AbstractApplicationContext.refresh()

getBeanFactory

public final ConfigurableListableBeanFactory getBeanFactory()
Description copied from class: AbstractApplicationContext
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.

Specified by:
getBeanFactory in interface ConfigurableApplicationContext
Specified by:
getBeanFactory in class AbstractApplicationContext
Returns:
this application context's internal bean factory
See Also:
AbstractApplicationContext.refresh()

createBeanFactory

protected DefaultListableBeanFactory createBeanFactory()
Create the bean factory for this context.

Default implementation creates a DefaultListableBeanFactory with the internal bean factory of this context's parent as parent bean factory.

Can be overridden in subclasses.

Returns:
the bean factory for this context
See Also:
DefaultListableBeanFactory, AbstractApplicationContext.getInternalParentBeanFactory()

loadBeanDefinitions

protected abstract void loadBeanDefinitions(DefaultListableBeanFactory beanFactory)
                                     throws IOException,
                                            BeansException
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:
IOException - if loading of bean definition files failed
BeansException - if parsing of the bean definitions failed
See Also:
PropertiesBeanDefinitionReader, XmlBeanDefinitionReader


Copyright (C) 2003-2004 The Spring Framework Project.