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.
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,
- Easy Integration With AOP
- Support for internationalization.
- 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.BeanFactory actually implements applicationcontext.
Example to Use BeanFactory and ApplicationContent in real world
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 ?
Examples Of ApplicationContext
As you are aware application context is programmatically a Java Interface . Have a look at few examples those are implementation of ApplicationContext.
- XmlWebApplicationContext
- AnnotationConfigWebApplicationContext
- AnnotationConfigApplicationContext
Explore More Spring Related Articles