Interface ApplicationContextAware

All Known Implementing Classes:
AbstractCachingViewResolver, AbstractCommandController, AbstractController, AbstractExcelView, AbstractFormController, AbstractHandlerMapping, AbstractJasperReportsSingleFormatView, AbstractJasperReportsView, AbstractJExcelView, AbstractPathMapHandlerMapping, AbstractPdfView, AbstractTemplateView, AbstractTemplateViewResolver, AbstractUrlBasedView, AbstractUrlHandlerMapping, AbstractUrlViewController, AbstractView, AbstractWizardFormController, AbstractXsltView, ApplicationObjectSupport, BaseCommandController, BeanNameUrlHandlerMapping, BeanNameViewResolver, CancellableFormController, CommonsPathMapHandlerMapping, FreeMarkerView, FreeMarkerViewResolver, InternalResourceView, InternalResourceViewResolver, JasperReportsCsvView, JasperReportsHtmlView, JasperReportsMultiFormatView, JasperReportsPdfView, JasperReportsViewResolver, JasperReportsXlsView, JobDetailBean, JstlView, MultiActionController, ParameterizableViewController, RedirectView, ResourceBundleViewResolver, SchedulerFactoryBean, ServletForwardingController, ServletWrappingController, SimpleFormController, SimpleUrlHandlerMapping, TilesConfigurer, TilesJstlView, TilesView, UrlBasedViewResolver, UrlFilenameViewController, VelocityLayoutView, VelocityLayoutViewResolver, VelocityToolboxView, VelocityView, VelocityViewResolver, WebApplicationObjectSupport, WebContentGenerator, WebContentInterceptor, XmlViewResolver

public interface ApplicationContextAware

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, or access to the MessageSource. However, it is preferable to implement the more specific ResourceLoaderAware interface or receive a reference to the MessageSource bean in that scenario.

Note that 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.

Rod Johnson
See Also:
ResourceLoaderAware, ApplicationObjectSupport, BeanFactoryAware, InitializingBean, BeanFactory

Method Summary
 void setApplicationContext(ApplicationContext applicationContext)
          Set the ApplicationContext that this object runs in.

Method Detail


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 like InitializingBean's afterPropertiesSet or a custom init-method. Invoked after ResourceLoaderAware's setResourceLoader.

applicationContext - ApplicationContext object to be used by this object
ApplicationContextException - in case of applicationContext initialization errors
BeansException - if thrown by application applicationContext methods
See Also:

Copyright (c) 2002-2007 The Spring Framework Project.