Spring Bean Aware Interfaces

Why do we need Spring Bean Aware Interfaces?

Sometimes spring bean might need access to different resource like ApplicationContext, BeanFactory. Spring Framework provides a set of interfaces that can help spring bean to get access of required resource.

Root Interface

Aware Interface

  • Aware interface is the root marker interface.
  • All the @@@Aware interfaces extends Aware interface and declares a set@@@ method.

Example : BeanNameAware interface extends Aware interface and declares a setBeanName method.

Different types of Aware interfaces

1. BeanNameAware

  • setBeanName method makes bean aware of its name defined in container (Application Context).

2. BeanFactoryAware

  • setBeanFactory method makes bean aware of its Bean Factory that created the bean.

3. ApplicationContextAware

  • setApplicationContext method makes bean aware of its Application Context.

4. BeanClassLoaderAware

  • setBeanClassLoader method makes bean aware of its class loader.

5. ServletContextAware

6. ServletConfigAware

7. ResourceLoaderAware

8. MessageSourceAware

9. ApplicationEventPublisherAware

10. BootstrapContextAware

11. LoadTimeWeaverAware

12. NotificationPublisherAware

13. PortletConfigAware

14. PortletContextAware