接口 ApplicationContextAware

所有超级接口:
Aware
所有已知实现类:
ApplicationContextSupport, ConfigurationPropertiesBindingPostProcessor, EventListenerMethodProcessor, LocalValidatorFactoryBean, OptionalValidatorFactoryBean, ScheduledAnnotationBeanPostProcessor

public interface ApplicationContextAware extends 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 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.

ApplicationContextSupport 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, Juergen Hoeller, Chris Beams, TODAY
2018-07-17 21:35:52
另请参阅:
  • 方法概要

    修饰符和类型
    方法
    说明
    void
    Set the ApplicationContext that this object runs in.