Major Difference Between ApplicationContext and BeanFactory in Spring Framework

InversionOfControl ApplicationContext and BeanFactory Spring Framework

Major Difference Between ApplicationContext and BeanFactory in Spring Framework :-

We are covering  Difference Between ApplicationContext and BeanFactory and Concepts of Inversion of Control (IOC) ApplicationContext vs BeanFactory vs WebApplicationContext . We will understand the basics of IOC and How ApplicationContext and BeanFactory work together.

Inversion Of Control:-

In a traditional application, the number of objects form together to make the application functionally working , hence the objects of application are dependencies to each other. We use numerous design patterns like Factory , Builder , Decorator to create various classes and create objects for the application . These patterns are best practices used by developers in order to address various problems .

The Spring Framework Inversion of Control (IOC) component or IOC Container provides a formalized means of composing different components into a fully working application ready for use, codifying these patterns.

3 IOC Container and Application Context

Dependency Injection and IOC Container:-

Dependency injection (DI) is the implementation of IOC. The process of injecting objects into another object or class dependency is achieved through an assembler or a central configuration engine or an IOC Container. This container is responsible for assembling objects and supply wherever required.

So we need an IOC Container in a framework. The Spring framework also has an IOC Container in the form of ApplicationContext. 

There are several implementations of the ApplicationContext interface as shown above. Now you must be wondering why I haven’t discussed BeanFactory. Let’s understand the difference now.

BeanFactory VS AplicationContext Vs WebApplicationContext:-

So ApplicationContext in Spring framework is built on top on BeanFactory and adds some extra functionality such as,

  1. Easy Integration With AOP
  2. Support for internationalization.
  3. Event Propagation

BeanFactory provides Core Configuration framework with basic functionalities, whereas Application context is with some more enhanced functionalities and more of  J2EE enterprise-centric.

1 ApplicationContext and BeanFactory

Where to Use What?

Usage Scenario of BeanFactory is if you are more concerned about memory consumption and you don’t require all features of ApplicationContext, for eg- In an Applet environment where each memory bytes is important.

Usage Scenario of ApplicationContext is when building most applications in a J2EE-environment, the best option is to use the ApplicationContext since it offers all the features and functionalities of the BeanFactory. It also allows adding some additional customization on top of it.

Please let me know in comments below  Did  you understood the basic concept of BeanFactory and ApplicationContext ?


Please enter your comment!
Please enter your name here