| java.lang.Object org.springframework.core.io.DefaultResourceLoader org.springframework.context.support.AbstractApplicationContext
All known Subclasses: org.springframework.context.support.GenericApplicationContext, org.springframework.context.support.AbstractRefreshableApplicationContext,
AbstractApplicationContext | abstract public class AbstractApplicationContext extends DefaultResourceLoader implements ConfigurableApplicationContext,DisposableBean(Code) | | Abstract implementation of the
org.springframework.context.ApplicationContext interface. Doesn't mandate the type of storage used for configuration; simply
implements common context functionality. Uses the Template Method design pattern,
requiring concrete subclasses to implement abstract methods.
In contrast to a plain BeanFactory, an ApplicationContext is supposed
to detect special beans defined in its internal bean factory:
Therefore, this class automatically registers
org.springframework.beans.factory.config.BeanFactoryPostProcessor BeanFactoryPostProcessors ,
org.springframework.beans.factory.config.BeanPostProcessor BeanPostProcessors and
org.springframework.context.ApplicationListener ApplicationListeners which are defined as beans in the context.
A
org.springframework.context.MessageSource may also be supplied
as a bean in the context, with the name "messageSource"; else, message
resolution is delegated to the parent context. Furthermore, a multicaster
for application events can be supplied as "applicationEventMulticaster" bean
of type
org.springframework.context.event.ApplicationEventMulticaster in the context; else, a default multicaster of type
org.springframework.context.event.SimpleApplicationEventMulticaster will be used.
Implements resource loading through extending
org.springframework.core.io.DefaultResourceLoader .
Consequently treats non-URL resource paths as class path resources
(supporting full class path resource names that include the package path,
e.g. "mypackage/myresource.dat"), unless the
AbstractApplicationContext.getResourceByPath method is overwritten in a subclass.
author: Rod Johnson author: Juergen Hoeller since: January 21, 2001 See Also: AbstractApplicationContext.refreshBeanFactory See Also: AbstractApplicationContext.getBeanFactory See Also: org.springframework.beans.factory.config.BeanFactoryPostProcessor See Also: org.springframework.beans.factory.config.BeanPostProcessor See Also: org.springframework.context.event.ApplicationEventMulticaster See Also: org.springframework.context.ApplicationListener See Also: org.springframework.context.MessageSource |
Method Summary | |
public void | addApplicationListener(ApplicationListener listener) | public void | addBeanFactoryPostProcessor(BeanFactoryPostProcessor beanFactoryPostProcessor) | protected void | addListener(ApplicationListener listener) Subclasses can invoke this method to register a listener. | public void | close() Close this application context, destroying all beans in its bean factory. | abstract protected void | closeBeanFactory() Subclasses must implement this method to release their internal bean factory. | public boolean | containsBean(String name) | public boolean | containsBeanDefinition(String name) | public boolean | containsLocalBean(String name) | public void | destroy() DisposableBean callback for destruction of this instance. | protected void | destroyBeans() Template method for destroying all beans that this context manages. | protected void | doClose() Actually performs context closing: publishes a ContextClosedEvent and
destroys the singletons in the bean factory of this application context. | public String[] | getAliases(String name) | public List | getApplicationListeners() Return the list of statically specified ApplicationListeners. | public AutowireCapableBeanFactory | getAutowireCapableBeanFactory() Return this context's internal bean factory as AutowireCapableBeanFactory,
if already available. | public Object | getBean(String name) | public Object | getBean(String name, Class requiredType) | public int | getBeanDefinitionCount() | public String[] | getBeanDefinitionNames() | abstract public ConfigurableListableBeanFactory | getBeanFactory() Subclasses must return their internal bean factory here. | public List | getBeanFactoryPostProcessors() Return the list of BeanFactoryPostProcessors that will get applied
to the internal BeanFactory. | public String[] | getBeanNamesForType(Class type) | public String[] | getBeanNamesForType(Class type, boolean includePrototypes, boolean allowEagerInit) | public Map | getBeansOfType(Class type) | public Map | getBeansOfType(Class type, boolean includePrototypes, boolean allowEagerInit) | public String | getDisplayName() Return a friendly name for this context. | protected BeanFactory | getInternalParentBeanFactory() Return the internal bean factory of the parent context if it implements
ConfigurableApplicationContext; else, return the parent context itself. | protected MessageSource | getInternalParentMessageSource() Return the internal message source of the parent context if it is an
AbstractApplicationContext too; else, return the parent context itself. | protected Collection | getLifecycleBeans() Return a Collection of all singleton beans that implement the
Lifecycle interface in this context. | public String | getMessage(String code, Object args, String defaultMessage, Locale locale) | public String | getMessage(String code, Object args, Locale locale) | public String | getMessage(MessageSourceResolvable resolvable, Locale locale) | public ApplicationContext | getParent() Return the parent context, or null if there is no parent
(that is, this context is the root of the context hierarchy). | public BeanFactory | getParentBeanFactory() | protected ResourcePatternResolver | getResourcePatternResolver() Return the ResourcePatternResolver to use for resolving location patterns
into Resource instances. | public Resource[] | getResources(String locationPattern) | public long | getStartupDate() Return the timestamp (ms) when this context was first loaded. | public Class | getType(String name) | protected void | initApplicationEventMulticaster() Initialize the ApplicationEventMulticaster. | protected void | initMessageSource() Initialize the MessageSource. | protected void | invokeBeanFactoryPostProcessors(ConfigurableListableBeanFactory beanFactory) Instantiate and invoke all registered BeanFactoryPostProcessor beans,
respecting explicit order if given. | public boolean | isActive() | public boolean | isPrototype(String name) | public boolean | isRunning() | public boolean | isSingleton(String name) | public boolean | isTypeMatch(String name, Class targetType) | protected ConfigurableListableBeanFactory | obtainFreshBeanFactory() Tell the subclass to refresh the internal bean factory. | protected void | onClose() Template method which can be overridden to add context-specific shutdown work.
The default implementation is empty.
Called at the end of
AbstractApplicationContext.doClose 's shutdown procedure, after
this context's BeanFactory has been closed. | protected void | onRefresh() Template method which can be overridden to add context-specific refresh work. | protected void | postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) Modify the application context's internal bean factory after its standard
initialization. | protected void | prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) Configure the factory's standard context characteristics,
such as the context's ClassLoader and post-processors. | protected void | prepareRefresh() Prepare this context for refreshing, setting its startup date and
active flag. | public void | publishEvent(ApplicationEvent event) Publish the given event to all listeners.
Note: Listeners get initialized after the MessageSource, to be able
to access it within listener implementations. | public void | refresh() | abstract protected void | refreshBeanFactory() Subclasses must implement this method to perform the actual configuration load.
The method is invoked by
AbstractApplicationContext.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 BeanFactory instance that it holds. | protected void | registerBeanPostProcessors(ConfigurableListableBeanFactory beanFactory) Instantiate and invoke all registered BeanPostProcessor beans,
respecting explicit order if given. | protected void | registerListeners() Add beans that implement ApplicationListener as listeners. | public void | registerShutdownHook() Register a shutdown hook with the JVM runtime, closing this context
on JVM shutdown unless it has already been closed at that time. | public void | setDisplayName(String displayName) Set a friendly name for this context. | public void | setParent(ApplicationContext parent) | public void | start() | public void | stop() | public String | toString() Return information about this context. |
MESSAGE_SOURCE_BEAN_NAME | final public static String MESSAGE_SOURCE_BEAN_NAME(Code) | | Name of the MessageSource bean in the factory.
If none is supplied, message resolution is delegated to the parent.
See Also: MessageSource |
logger | final protected Log logger(Code) | | Logger used by this class. Available to subclasses.
|
AbstractApplicationContext | public AbstractApplicationContext()(Code) | | Create a new AbstractApplicationContext with no parent.
|
AbstractApplicationContext | public AbstractApplicationContext(ApplicationContext parent)(Code) | | Create a new AbstractApplicationContext with the given parent context.
Parameters: parent - the parent context |
addListener | protected void addListener(ApplicationListener listener)(Code) | | Subclasses can invoke this method to register a listener.
Any beans in the context that are listeners are automatically added.
Parameters: listener - the listener to register |
closeBeanFactory | abstract protected void closeBeanFactory()(Code) | | Subclasses must implement this method to release their internal bean factory.
This method gets invoked by
AbstractApplicationContext.close() after all other shutdown work.
Should never throw an exception but rather log shutdown failures.
|
containsBeanDefinition | public boolean containsBeanDefinition(String name)(Code) | | |
containsLocalBean | public boolean containsLocalBean(String name)(Code) | | |
getBeanDefinitionCount | public int getBeanDefinitionCount()(Code) | | |
getBeanDefinitionNames | public String[] getBeanDefinitionNames()(Code) | | |
getBeanNamesForType | public String[] getBeanNamesForType(Class type, boolean includePrototypes, boolean allowEagerInit)(Code) | | |
getDisplayName | public String getDisplayName()(Code) | | Return a friendly name for this context.
|
getInternalParentMessageSource | protected MessageSource getInternalParentMessageSource()(Code) | | Return the internal message source of the parent context if it is an
AbstractApplicationContext too; else, return the parent context itself.
|
getLifecycleBeans | protected Collection getLifecycleBeans()(Code) | | Return a Collection of all singleton beans that implement the
Lifecycle interface in this context.
Collection of Lifecycle beans |
getParent | public ApplicationContext getParent()(Code) | | Return the parent context, or null if there is no parent
(that is, this context is the root of the context hierarchy).
|
getStartupDate | public long getStartupDate()(Code) | | Return the timestamp (ms) when this context was first loaded.
|
initMessageSource | protected void initMessageSource()(Code) | | Initialize the MessageSource.
Use parent's if none defined in this context.
|
invokeBeanFactoryPostProcessors | protected void invokeBeanFactoryPostProcessors(ConfigurableListableBeanFactory beanFactory)(Code) | | Instantiate and invoke all registered BeanFactoryPostProcessor beans,
respecting explicit order if given.
Must be called before singleton instantiation.
|
isActive | public boolean isActive()(Code) | | |
isRunning | public boolean isRunning()(Code) | | |
onClose | protected void onClose()(Code) | | Template method which can be overridden to add context-specific shutdown work.
The default implementation is empty.
Called at the end of
AbstractApplicationContext.doClose 's shutdown procedure, after
this context's BeanFactory has been closed. If custom shutdown logic
needs to execute while the BeanFactory is still active, override
the
AbstractApplicationContext.destroyBeans() method instead.
|
postProcessBeanFactory | protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)(Code) | | Modify the application context's internal bean factory after its standard
initialization. All bean definitions will have been loaded, but no beans
will have been instantiated yet. This allows for registering special
BeanPostProcessors etc in certain ApplicationContext implementations.
Parameters: beanFactory - the bean factory used by the application context |
prepareBeanFactory | protected void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory)(Code) | | Configure the factory's standard context characteristics,
such as the context's ClassLoader and post-processors.
Parameters: beanFactory - the BeanFactory to configure |
prepareRefresh | protected void prepareRefresh()(Code) | | Prepare this context for refreshing, setting its startup date and
active flag.
|
publishEvent | public void publishEvent(ApplicationEvent event)(Code) | | Publish the given event to all listeners.
Note: Listeners get initialized after the MessageSource, to be able
to access it within listener implementations. Thus, MessageSource
implementations cannot publish events.
Parameters: event - the event to publish (may be application-specific or astandard framework event) |
refreshBeanFactory | abstract protected void refreshBeanFactory() throws BeansException, IllegalStateException(Code) | | Subclasses must implement this method to perform the actual configuration load.
The method is invoked by
AbstractApplicationContext.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 BeanFactory instance that it holds. In the latter case, it will
usually throw an IllegalStateException if refreshing the context more than once.
throws: BeansException - if initialization of the bean factory failed throws: IllegalStateException - if already initialized and multiple refreshattempts are not supported |
registerBeanPostProcessors | protected void registerBeanPostProcessors(ConfigurableListableBeanFactory beanFactory)(Code) | | Instantiate and invoke all registered BeanPostProcessor beans,
respecting explicit order if given.
Must be called before any instantiation of application beans.
|
registerListeners | protected void registerListeners()(Code) | | Add beans that implement ApplicationListener as listeners.
Doesn't affect other listeners, which can be added without being beans.
|
setDisplayName | public void setDisplayName(String displayName)(Code) | | Set a friendly name for this context.
Typically done during initialization of concrete context implementations.
|
start | public void start()(Code) | | |
toString | public String toString()(Code) | | Return information about this context.
|
|
|