Top Description Methods
org.springframework.context

public Interface ApplicationContextAware

extends Aware
Known Direct Implementers
org.springframework.context.event.EventListenerMethodProcessor, org.springframework.context.support.ApplicationObjectSupport, org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor, org.springframework.scheduling.concurrent.ExecutorConfigurationSupport, org.springframework.scheduling.concurrent.SimpleAsyncTaskScheduler, org.springframework.validation.beanvalidation.LocalValidatorFactoryBean
Imports
org.springframework.beans.BeansException, org.springframework.beans.factory.Aware

Interface to be implemented by any object that wishes to be notified of the 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 org.springframework.core.io.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.

org.springframework.context.support.ApplicationObjectSupport is a convenience base class for application objects, implementing this interface.

For a list of all bean lifecycle methods, see the BeanFactory javadocs.

Authors
Rod Johnson, Juergen Hoeller, Chris Beams
See Also
ResourceLoaderAware, ApplicationEventPublisherAware, MessageSourceAware, org.springframework.context.support.ApplicationObjectSupport, org.springframework.beans.factory.BeanFactoryAware

Method Summary

Modifier and TypeMethod and Description
public void
setApplicationContext(ApplicationContext
the ApplicationContext object to be used by this object
applicationContext
)

Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.

Method Detail

setApplicationContextback to summary
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException

Set the ApplicationContext that this object runs in. Normally this call will be used to initialize the object.

Invoked after population of normal bean properties but before an init callback such as org.springframework.beans.factory.InitializingBean#afterPropertiesSet() or a custom init-method. Invoked after ResourceLoaderAware#setResourceLoader, ApplicationEventPublisherAware#setApplicationEventPublisher and MessageSourceAware, if applicable.

Parameters
applicationContext:ApplicationContext

the ApplicationContext object to be used by this object

Exceptions
BeansException:
if thrown by application context methods
ApplicationContextException:
in case of context initialization errors
See Also
org.springframework.beans.factory.BeanInitializationException