public interface ApplicationContextAware extends Aware
ApplicationContext
that it runs in.
Implementing this interface makes sense for example when an object requires access to a set of collaborating beans. Note that configuration via bean references is preferable to implementing this interface just for bean lookup purposes.
This interface can also be implemented if an object needs access to file
resources, i.e. wants to call getResource
, wants to publish
an application event, or requires access to the MessageSource. However,
it is preferable to implement the more specific ResourceLoaderAware
,
ApplicationEventPublisherAware
or MessageSourceAware
interface
in such a specific scenario.
Note that file resource dependencies can also be exposed as bean properties
of type Resource
, populated via Strings
with automatic type conversion by the bean factory. This removes the need
for implementing any callback interface just for the purpose of accessing
a specific file resource.
ApplicationObjectSupport
is a
convenience base class for application objects, implementing this interface.
For a list of all bean lifecycle methods, see the
BeanFactory javadocs
.
ResourceLoaderAware
,
ApplicationEventPublisherAware
,
MessageSourceAware
,
ApplicationObjectSupport
,
BeanFactoryAware
Modifier and Type | Method and Description |
---|---|
void |
setApplicationContext(ApplicationContext applicationContext)
Set the ApplicationContext that this object runs in.
|
void setApplicationContext(ApplicationContext applicationContext) throws BeansException
Invoked after population of normal bean properties but before an init callback such
as InitializingBean.afterPropertiesSet()
or a custom init-method. Invoked after ResourceLoaderAware.setResourceLoader(org.springframework.core.io.ResourceLoader)
,
ApplicationEventPublisherAware.setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher)
and
MessageSourceAware
, if applicable.
applicationContext
- the ApplicationContext object to be used by this objectApplicationContextException
- in case of context initialization errorsBeansException
- if thrown by application context methodsBeanInitializationException