Difference between Application context and Beanfactory in Spring framework

SpringObject Oriented ProgrammingProgramming

Spring framework provides two IOC container for managing, configuring and manipulating beans. One is BeanFactory and the other is Application Context. 

The application context interface extends BeanFactory to enhance the functionality of BeanFactory. 

In new Spring versions, BeanFactory is replaced with ApplicationContext. But still, BeanFactory exists for backward compatibility. 

Spring version 2.0 and above, is used BeanPostProcessor extension point(Interface which provides some callback methods that we can implement to customize the instantiation logic, dependency-resolution logic and etc ). So, if you are using BeanFactory then some of the functionality such as AOP and transaction will not work without doing some extra configuration.

Sr. No.KeyBeanfactoryApplication context
1
Implementation 
XMLBeanFactory implements BeanFactory 
FileSystemXmlApplicationContext, ClassPathXmlApplicationContext and AnnotationConfigWebApplicationContex implements ApplicationContext. 

Also, ApplicationContext extends Beanfactory 
2
Annotation 
No
Yes
3
instantiation
Benafactory instantiate beans when  getBean() method gets called.
Application instainte bean at the time container start.
4
Event Publication 
Bean factory does not have the ability to push events to the beans 
Application Context have ability to push to push events to the beans.
5
Loading Mechanism
Lazy loading 
Aggressive Loading 
raja
Published on 18-Nov-2019 11:56:41
Advertisements