|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.core.io.DefaultResourceLoader org.springframework.context.support.AbstractApplicationContext org.springframework.context.support.AbstractRefreshableApplicationContext
public abstract class AbstractRefreshableApplicationContext
Base class for ApplicationContext
implementations which 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(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.
loadBeanDefinitions(org.springframework.beans.factory.support.DefaultListableBeanFactory)
,
DefaultListableBeanFactory
,
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.context.ConfigurableApplicationContext |
---|
CONFIG_LOCATION_DELIMITERS, LOAD_TIME_WEAVER_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_ALL_URL_PREFIX |
Fields inherited from interface org.springframework.core.io.ResourceLoader |
---|
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 void |
closeBeanFactory()
Subclasses must implement this method to release their internal bean factory. |
protected DefaultListableBeanFactory |
createBeanFactory()
Create an internal bean factory for this context. |
protected void |
customizeBeanFactory(DefaultListableBeanFactory beanFactory)
Customize the internal bean factory used by this context. |
ConfigurableListableBeanFactory |
getBeanFactory()
Subclasses must return their internal bean factory here. |
protected 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. |
protected 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. |
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. |
Methods inherited from class org.springframework.core.io.DefaultResourceLoader |
---|
getClassLoader, getResource, getResourceByPath, setClassLoader |
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 |
---|
getClassLoader, getResource |
Constructor Detail |
---|
public AbstractRefreshableApplicationContext()
public AbstractRefreshableApplicationContext(ApplicationContext parent)
parent
- the parent contextMethod Detail |
---|
public void setAllowBeanDefinitionOverriding(boolean allowBeanDefinitionOverriding)
DefaultListableBeanFactory.setAllowBeanDefinitionOverriding(boolean)
public void setAllowCircularReferences(boolean allowCircularReferences)
Default is "true". Turn this off to throw an exception when encountering a circular reference, disallowing them completely.
AbstractAutowireCapableBeanFactory.setAllowCircularReferences(boolean)
protected final void refreshBeanFactory() throws BeansException
refreshBeanFactory
in class AbstractApplicationContext
BeansException
- if initialization of the bean factory failedprotected final void closeBeanFactory()
AbstractApplicationContext
AbstractApplicationContext.close()
after all other shutdown work.
Should never throw an exception but rather log shutdown failures.
closeBeanFactory
in class AbstractApplicationContext
protected final boolean hasBeanFactory()
public final ConfigurableListableBeanFactory getBeanFactory()
AbstractApplicationContext
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.
getBeanFactory
in interface ConfigurableApplicationContext
getBeanFactory
in class AbstractApplicationContext
null
)AbstractApplicationContext.refreshBeanFactory()
,
AbstractApplicationContext.closeBeanFactory()
protected DefaultListableBeanFactory createBeanFactory()
AbstractApplicationContext.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.
DefaultListableBeanFactory.setAllowBeanDefinitionOverriding(boolean)
,
DefaultListableBeanFactory.setAllowEagerClassLoading(boolean)
,
AbstractAutowireCapableBeanFactory.setAllowCircularReferences(boolean)
,
AbstractAutowireCapableBeanFactory.setAllowRawInjectionDespiteWrapping(boolean)
protected void customizeBeanFactory(DefaultListableBeanFactory beanFactory)
AbstractApplicationContext.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.
beanFactory
- the newly created bean factory for this contextDefaultListableBeanFactory.setAllowBeanDefinitionOverriding(boolean)
,
AbstractAutowireCapableBeanFactory.setAllowCircularReferences(boolean)
,
AbstractAutowireCapableBeanFactory.setAllowRawInjectionDespiteWrapping(boolean)
,
DefaultListableBeanFactory.setAllowEagerClassLoading(boolean)
protected abstract void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws IOException, BeansException
beanFactory
- the bean factory to load bean definitions into
IOException
- if loading of bean definition files failed
BeansException
- if parsing of the bean definitions failedPropertiesBeanDefinitionReader
,
XmlBeanDefinitionReader
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |