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
BeanFactoryPostProcessors,
BeanPostProcessors,
and ApplicationListeners
which are defined as beans in the context.
A org. may also be supplied
as a bean in the context, with the name "messageSource"; otherwise, message
resolution is delegated to the parent context. Furthermore, a multicaster
for application events can be supplied as an "applicationEventMulticaster" bean
of type org.
in the context; otherwise, a default multicaster of type
org. will be used.
Implements resource loading by extending
org..
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 getResourceByPath
method is overridden in a subclass.
refreshBeanFactory, getBeanFactory, org.springframework.beans.factory.config.BeanFactoryPostProcessor , org.springframework.beans.factory.config.BeanPostProcessor , org.springframework.context.event.ApplicationEventMulticaster , org.springframework.context.ApplicationListener , org.springframework.context.MessageSource
| Modifier and Type | Field and Description |
|---|---|
| private final AtomicBoolean | active
Flag that indicates whether this context is currently active. |
| public static final String | APPLICATION_EVENT_MULTICASTER_BEAN_NAME
The name of the |
| private ApplicationEventMulticaster | applicationEventMulticaster
Helper class used in event publishing. |
| private final Set | applicationListeners
Statically specified listeners. |
| private ApplicationStartup | applicationStartup
Application startup metrics. |
| private final List | beanFactoryPostProcessors
BeanFactoryPostProcessors to apply on refresh. |
| private final AtomicBoolean | closed
Flag that indicates whether this context has been closed already. |
| private String | displayName
Display name. |
| private Set | earlyApplicationEvents
ApplicationEvents published before the multicaster setup. |
| private Set | earlyApplicationListeners
Local listeners registered before refresh. |
| private ConfigurableEnvironment | environment
Environment used by this context. |
| private String | id
Unique id for this context, if any. |
| public static final String | LIFECYCLE_PROCESSOR_BEAN_NAME
The name of the |
| private LifecycleProcessor | lifecycleProcessor
LifecycleProcessor for managing the lifecycle of beans within this context. |
| protected final Log | logger
Logger used by this class. |
| public static final String | MESSAGE_SOURCE_BEAN_NAME
The name of the |
| private MessageSource | messageSource
MessageSource we delegate our implementation of this interface to. |
| private ApplicationContext | parent
Parent context. |
| private final ResourcePatternResolver | resourcePatternResolver
ResourcePatternResolver used by this context. |
| private Thread | shutdownHook
Reference to the JVM shutdown hook, if registered. |
| private long | startupDate
System time in milliseconds when this context started. |
| private final Lock | startupShutdownLock
Synchronization lock for "refresh" and "close". |
| private volatile Thread | startupShutdownThread
Currently active startup/shutdown thread. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | AbstractApplicationContext(ApplicationContext
the parent context parent)Create a new AbstractApplicationContext with the given parent context. |
| Modifier and Type | Method and Description |
|---|---|
| public void | addApplicationListener(ApplicationListener<?>
the ApplicationListener to register listener)Implements org. |
| public void | addBeanFactoryPostProcessor(BeanFactoryPostProcessor
the factory processor to register postProcessor)Implements org. |
| protected void | assertBeanFactoryActive()
Assert that this context's BeanFactory is currently active,
throwing an |
| protected void | cancelRefresh(Throwable
the exception that led to the cancellation ex)Cancel this context's refresh attempt, resetting the |
| public void | close()
Implements org. |
| protected abstract void | |
| public boolean | containsBean(String
the name of the bean to query name)Implements org. |
| public boolean | containsBeanDefinition(String
the name of the bean to look for beanName)Implements org. |
| public boolean | containsLocalBean(String
the name of the bean to query name)Implements org. |
| protected ConfigurableEnvironment | |
| protected void | |
| protected void | doClose()
Actually performs context closing: publishes a ContextClosedEvent and destroys the singletons in the bean factory of this application context. |
| public <A extends Annotation> Set | findAllAnnotationsOnBean(String
the name of the bean to look for annotations on beanName, Class<A> the type of annotation to look for
(at class, interface or factory method level of the specified bean) annotationType, boolean whether a allowFactoryBeanInit)FactoryBean may get initialized
just for the purpose of determining its object typeImplements org. Annotation instances of annotationType on the specified
bean, traversing its interfaces and superclasses if no annotation can be found on
the given class itself, as well as checking the bean's factory method (if any).
|
| public <A extends Annotation> A | findAnnotationOnBean(String
the name of the bean to look for annotations on beanName, Class<A> the type of annotation to look for
(at class, interface or factory method level of the specified bean) annotationType)Implements org. Annotation of annotationType on the specified bean,
traversing its interfaces and superclasses if no annotation can be found on
the given class itself, as well as checking the bean's factory method (if any).
|
| public <A extends Annotation> A | findAnnotationOnBean(String
the name of the bean to look for annotations on beanName, Class<A> the type of annotation to look for
(at class, interface or factory method level of the specified bean) annotationType, boolean whether a allowFactoryBeanInit)FactoryBean may get initialized
just for the purpose of determining its object typeImplements org. Annotation of annotationType on the specified bean,
traversing its interfaces and superclasses if no annotation can be found on
the given class itself, as well as checking the bean's factory method (if any).
|
| protected void | finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory)
Finish the initialization of this context's bean factory, initializing all remaining singleton beans. |
| protected void | finishRefresh()
Finish the refresh of this context, invoking the LifecycleProcessor's
onRefresh() method and publishing the
|
| public String[] | getAliases(String
the bean name to check for aliases name)Implements org. |
| pack-priv ApplicationEventMulticaster | Returns: the internal ApplicationEventMulticaster (nevernull)Return the internal ApplicationEventMulticaster used by the context. |
| public Collection | |
| public String | getApplicationName()
Implements org. |
| public ApplicationStartup | getApplicationStartup()
Implements org. ApplicationStartup for this application context.
|
| public AutowireCapableBeanFactory | getAutowireCapableBeanFactory()
Implements org. |
| public Object | getBean(String
the name of the bean to retrieve name)Implements org. |
| public <T> T | getBean(String
the name of the bean to retrieve name, Class<T> type the bean must match; can be an interface or superclass requiredType)Implements org. |
| public Object | getBean(String
the name of the bean to retrieve name, Object... arguments to use when creating a bean instance using explicit arguments
(only applied when creating a new instance as opposed to retrieving an existing one) args)Implements org. |
| public <T> T | getBean(Class<T>
type the bean must match; can be an interface or superclass requiredType)Implements org. |
| public <T> T | getBean(Class<T>
type the bean must match; can be an interface or superclass requiredType, Object... arguments to use when creating a bean instance using explicit arguments
(only applied when creating a new instance as opposed to retrieving an existing one) args)Implements org. |
| public int | getBeanDefinitionCount()
Implements org. |
| public String[] | getBeanDefinitionNames()
Implements org. |
| public abstract ConfigurableListableBeanFactory | Returns: this application context's internal bean factory (nevernull)Redeclares org. |
| public List | getBeanFactoryPostProcessors()
Return the list of BeanFactoryPostProcessors that will get applied to the internal BeanFactory. |
| public String[] | getBeanNamesForAnnotation(Class<? extends Annotation>
the type of annotation to look for
(at class, interface or factory method level of the specified bean) annotationType)Implements org. Annotation
type, without creating corresponding bean instances yet.
|
| public String[] | getBeanNamesForType(ResolvableType
the generically typed class or interface to match type)Implements org. getObjectType
in the case of FactoryBeans.
|
| public String[] | getBeanNamesForType(ResolvableType
the generically typed class or interface to match type, boolean whether to include prototype or scoped beans too
or just singletons (also applies to FactoryBeans) includeNonSingletons, boolean whether to initialize lazy-init singletons and
objects created by FactoryBeans (or by factory methods with a
"factory-bean" reference) for the type check. Note that FactoryBeans need to be
eagerly initialized to determine their type: So be aware that passing in "true"
for this flag will initialize FactoryBeans and "factory-bean" references. allowEagerInit)Implements org. getObjectType
in the case of FactoryBeans.
|
| public String[] | getBeanNamesForType(Class<?>
the class or interface to match, or type)null for all bean namesImplements org. getObjectType
in the case of FactoryBeans.
|
| public String[] | getBeanNamesForType(Class<?>
the class or interface to match, or type, boolean null for all bean nameswhether to include prototype or scoped beans too
or just singletons (also applies to FactoryBeans) includeNonSingletons, boolean whether to initialize lazy-init singletons and
objects created by FactoryBeans (or by factory methods with a
"factory-bean" reference) for the type check. Note that FactoryBeans need to be
eagerly initialized to determine their type: So be aware that passing in "true"
for this flag will initialize FactoryBeans and "factory-bean" references. allowEagerInit)Implements org. getObjectType
in the case of FactoryBeans.
|
| public <T> ObjectProvider | getBeanProvider(Class<T>
type the bean must match; can be an interface or superclass requiredType)Implements org. |
| public <T> ObjectProvider | getBeanProvider(ResolvableType
type the bean must match; can be a generic type declaration requiredType)Implements org. |
| public <T> ObjectProvider | getBeanProvider(Class<T>
type the bean must match; can be an interface or superclass requiredType, boolean whether stream-based access may initialize lazy-init
singletons and objects created by FactoryBeans (or by factory methods
with a "factory-bean" reference) for the type check allowEagerInit)Implements org. |
| public <T> ObjectProvider | getBeanProvider(ResolvableType
type the bean must match; can be a generic type declaration.
Note that collection types are not supported here, in contrast to reflective
injection points. For programmatically retrieving a list of beans matching a
specific type, specify the actual bean type as an argument here and subsequently
use requiredType, boolean ObjectProvider#orderedStream() or its lazy streaming/iteration options.whether stream-based access may initialize lazy-init
singletons and objects created by FactoryBeans (or by factory methods
with a "factory-bean" reference) for the type check allowEagerInit)Implements org. |
| public <T> Map | getBeansOfType(Class<T>
the class or interface to match, or type)null for all concrete beansImplements org. getObjectType in the case of FactoryBeans.
|
| public <T> Map | getBeansOfType(Class<T>
the class or interface to match, or type, boolean null for all concrete beanswhether to include prototype or scoped beans too
or just singletons (also applies to FactoryBeans) includeNonSingletons, boolean whether to initialize lazy-init singletons and
objects created by FactoryBeans (or by factory methods with a
"factory-bean" reference) for the type check. Note that FactoryBeans need to be
eagerly initialized to determine their type: So be aware that passing in "true"
for this flag will initialize FactoryBeans and "factory-bean" references. allowEagerInit)Implements org. getObjectType in the case of FactoryBeans.
|
| public Map | getBeansWithAnnotation(Class<? extends Annotation>
the type of annotation to look for
(at class, interface or factory method level of the specified bean) annotationType)Implements org. Annotation type,
returning a Map of bean names with corresponding bean instances.
|
| public String | Returns: a display name for this context (nevernull)Implements org. |
| public ConfigurableEnvironment | getEnvironment()
Implements org. Environment for this application context in configurable
form, allowing for further customization.
|
| public String | getId()
Implements org. |
| 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. |
| pack-priv LifecycleProcessor | Returns: the internal LifecycleProcessor (nevernull)Return the internal LifecycleProcessor used by the context. |
| public String | getMessage(String
the message code to look up, e.g. 'calculator.noRateSet'.
MessageSource users are encouraged to base message names on qualified class
or package names, avoiding potential conflicts and ensuring maximum clarity. code, Object[] an array of arguments that will be filled in for params within
the message (params look like "{0}", "{1,date}", "{2,time}" within a message),
or args, String null if nonea default message to return if the lookup fails defaultMessage, Locale the locale in which to do the lookup locale)Implements org. |
| public String | getMessage(String
the message code to look up, e.g. 'calculator.noRateSet'.
MessageSource users are encouraged to base message names on qualified class
or package names, avoiding potential conflicts and ensuring maximum clarity. code, Object[] an array of arguments that will be filled in for params within
the message (params look like "{0}", "{1,date}", "{2,time}" within a message),
or args, Locale null if nonethe locale in which to do the lookup locale)Implements org. |
| public String | getMessage(MessageSourceResolvable
the value object storing attributes required to resolve a message
(may include a default message) resolvable, Locale the locale in which to do the lookup locale)Implements org. MessageSourceResolvable argument that was passed in.Note We must throw a |
| private MessageSource | Returns: the internal MessageSource (nevernull)Return the internal MessageSource used by the context. |
| public ApplicationContext | getParent()
Implements org. null if there is no parent
(that is, this context is the root of the context hierarchy).
|
| public BeanFactory | getParentBeanFactory()
Implements org. null if there is none.
|
| protected ResourcePatternResolver | Returns: the ResourcePatternResolver for this contextReturn the ResourcePatternResolver to use for resolving location patterns into Resource instances. |
| public Resource[] | getResources(String
the location pattern to resolve locationPattern)Implements org. Resource objects.
|
| public long | getStartupDate()
Implements org. |
| public Class | getType(String
the name of the bean to query name)Implements org. |
| public Class | getType(String
the name of the bean to query name, boolean whether a allowFactoryBeanInit)FactoryBean may get initialized
just for the purpose of determining its object typeImplements org. |
| protected void | |
| protected void | |
| protected void | |
| protected void | |
| protected void | invokeBeanFactoryPostProcessors(ConfigurableListableBeanFactory beanFactory)
Instantiate and invoke all registered BeanFactoryPostProcessor beans, respecting explicit order if given. |
| public boolean | isActive()
Implements org. |
| public boolean | isPrototype(String
the name of the bean to query name)Implements org. |
| public boolean | isRunning()
Implements org. |
| public boolean | isSingleton(String
the name of the bean to query name)Implements org. |
| private boolean | isStartupShutdownThreadStuck()
Determine whether an active startup/shutdown thread is currently stuck,
e.g. through a |
| public boolean | isTypeMatch(String
the name of the bean to query name, ResolvableType the type to match against (as a typeToMatch)ResolvableType)Implements org. |
| public boolean | isTypeMatch(String
the name of the bean to query name, Class<?> the type to match against (as a typeToMatch)Class)Implements org. |
| protected ConfigurableListableBeanFactory | Returns: the fresh BeanFactory instanceTell the subclass to refresh the internal bean factory. |
| protected void | |
| protected void | |
| protected void | postProcessBeanFactory(ConfigurableListableBeanFactory
the bean factory used by the application context beanFactory)Modify the application context's internal bean factory after its standard initialization. |
| protected void | prepareBeanFactory(ConfigurableListableBeanFactory
the BeanFactory to configure 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 as well as performing any initialization of property sources. |
| public void | publishEvent(ApplicationEvent
the event to publish (may be application-specific or a
standard framework event) event)Overrides default org. |
| public void | publishEvent(Object
the event to publish (may be an event)ApplicationEvent
or a payload object to be turned into a PayloadApplicationEvent)Implements org. |
| protected void | publishEvent(Object
the event to publish (may be an event, ResolvableType ApplicationEvent
or a payload object to be turned into a PayloadApplicationEvent)the resolved event type, if known.
The implementation of this method also tolerates a payload type hint for
a payload object to be turned into a typeHint)PayloadApplicationEvent.
However, the recommended way is to construct an actual event object via
PayloadApplicationEvent#PayloadApplicationEvent(Object, Object, ResolvableType)
instead for such scenarios.Publish the given event to all listeners. |
| public void | refresh()
Implements org. |
| protected abstract void | |
| protected void | registerBeanPostProcessors(ConfigurableListableBeanFactory beanFactory)
Instantiate and register all BeanPostProcessor beans, respecting explicit order if given. |
| protected void | |
| public void | registerShutdownHook()
Implements org. SpringContextShutdownHook with the JVM runtime, closing this
context on JVM shutdown unless it has already been closed at that time.
|
| public void | removeApplicationListener(ApplicationListener<?>
the ApplicationListener to deregister listener)Implements org. addApplicationListener before.
|
| protected void | resetCommonCaches()
Reset Spring's common reflection metadata caches, in particular the
|
| public void | setApplicationStartup(ApplicationStartup
the new context event factory applicationStartup)Implements org. ApplicationStartup for this application context.
|
| public void | |
| public void | setEnvironment(ConfigurableEnvironment
the new environment environment)Implements org. Environment for this application context.
|
| public void | setId(String
the unique id of the context id)Implements org. |
| public void | setParent(ApplicationContext
the parent context parent)Implements org. |
| public void | |
| public void | stop()
Implements org. |
| public String |