Besides ApplicationContextAware and BeanNameAware (discussed earlier), Spring offers a wide range of Aware callback interfaces that let beans indicate to the container that they require a certain infrastructure dependency. As a general rule, the name indicates the dependency type. The following table summarizes the most important Aware interfaces:
Name | Injected Dependency | Explained in… |
---|---|---|
ApplicationContextAware |
Declaring ApplicationContext. |
|
ApplicationEventPublisherAware |
Event publisher of the enclosing ApplicationContext. |
|
BeanClassLoaderAware |
Class loader used to load the bean classes. |
|
BeanFactoryAware |
Declaring BeanFactory. |
|
BeanNameAware |
Name of the declaring bean. |
|
BootstrapContextAware |
Resource adapter BootstrapContextthe container runs in. Typically available only in JCA-aware ApplicationContext instances. |
|
LoadTimeWeaverAware |
Defined weaver for processing class definition at load time. |
|
MessageSourceAware |
Configured strategy for resolving messages (with support for parametrization and internationalization). |
|
NotificationPublisherAware |
Spring JMX notification publisher. |
|
ResourceLoaderAware |
Configured loader for low-level access to resources. |
|
ServletConfigAware |
Current ServletConfig the container runs in. Valid only in a web-aware Spring ApplicationContext. |
|
ServletContextAware |
Current ServletContext the container runs in. Valid only in a web-aware Spring ApplicationContext. |
Note again that using these interfaces ties your code to the Spring API and does not follow the Inversion of Control style. As a result, we recommend them for infrastructure beans that require programmatic access to the container.