📜  春季-IoC容器

📅  最后修改于: 2020-11-11 06:58:17             🧑  作者: Mango


Spring容器是Spring框架的核心。容器将创建对象,将它们连接在一起,进行配置,并管理从创建到销毁的整个生命周期。 Spring容器使用DI来管理组成应用程序的组件。这些对象称为Spring Bean,我们将在下一章中进行讨论。

容器通过读取提供的配置元数据来获取有关实例化,配置和组装哪些对象的指令。配置元数据可以用XML,Java批注或Java代码表示。下图是Spring工作原理的高级视图。 Spring IoC容器利用Java POJO类和配置元数据来生成完全配置且可执行的系统或应用程序。

春季IoC容器

Spring提供了以下两种不同类型的容器。

Sr.No. Container & Description
1 Spring BeanFactory Container

This is the simplest container providing the basic support for DI and is defined by the org.springframework.beans.factory.BeanFactory interface. The BeanFactory and related interfaces, such as BeanFactoryAware, InitializingBean, DisposableBean, are still present in Spring for the purpose of backward compatibility with a large number of third-party frameworks that integrate with Spring.

2 Spring ApplicationContext Container

This container adds more enterprise-specific functionality such as the ability to resolve textual messages from a properties file and the ability to publish application events to interested event listeners. This container is defined by the org.springframework.context.ApplicationContext interface.

ApplicationContext容器包含BeanFactory容器的所有功能,因此通常建议在BeanFactory上使用它。 BeanFactory仍可用于轻量级应用程序,例如移动设备或基于Applet的应用程序,这些应用程序的数据量和速度非常重要。