This is most common interview question asked on spring framework.

Differences between BeanFactory and ApplicationContext in Spring:

  • BeanFactory is a light-weight container that is used to instantiate, configure, and manage the beans.
    • It is the most basic container provided by Spring and is suitable for simple applications
    • It only provides the basic functionality of creating and managing beans.
    • Bean factory does not support annotation based configuration
  • ApplicationContext built on top of BeanFactory and provides additional functionalities to support
    • internationalization (I18N) messages
    • Application lifecycle events, and validation
    • Supports file-based configuration, for example reading in a XML file to configure the beans
    • It is more suitable for enterprise applications and provides more advanced features.
  • ApplicationContext also supports the use of annotation-based configuration.

Finally, the summary is : BeanFactory is a light-weight container that provides basic functionality for managing beans, whereas ApplicationContext is a more advanced container that provides additional functionality for enterprise applications and supports more advanced features such as annotation-based configuration.

Thanks for Reading.