English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

The difference between application context and Beanfactory in the Spring framework

The Spring framework provides two IOC containers for managing, configuring, and operating beans. One is BeanFactory, and the other is the application context. 

The ApplicationContext interface extends BeanFactory to enhance the functionality of BeanFactory. 

In the new Spring version, BeanFactory is replaced with ApplicationContext. However, the existence of BeanFactory is for backward compatibility. 

Spring 2Version 3.0 and higher use the BeanPostProcessor extension point (the interface provides some callback methods, which we can implement to customize instantiation logic, dependency resolution logic, etc.). Therefore, if you are using BeanFactory, some additional configuration is required to use certain features (such as AOP and transaction processing).

IndexKeyBean FactoryApplication Environment
1Each
Implementation 
XMLBeanFactory implements BeanFactory 
FileSystemXmlApplicationContext, ClassPathXmlApplicationContext, and AnnotationConfigWebApplicationContex implement ApplicationContext. 

In addition, ApplicationContext extends BeanFactory 
2
Annotation 
No
Yes
3
Instantiation
Bean factory instantiates beans when the getBean() method is called.
The application context applies instainte bean when the container starts.
4
Event Publication 
The bean factory does not have the ability to push events to the beans 
The application context has the ability to push events to the beans.
5
Loading Mechanism
Lazy Loading 
Aggressive Loading