Spring 简明教程
Spring - IoC Containers
Spring 容器是 Spring Framework 的核心。容器将创建对象,将它们连接在一起,配置它们,并管理它们从创建到销毁的整个生命周期。Spring 容器使用 DI 来管理构成应用程序的组件。这些对象称为 Spring Bean,我们将在下一章中讨论它们。
The Spring container is at the core of the Spring Framework. The container will create the objects, wire them together, configure them, and manage their complete life cycle from creation till destruction. The Spring container uses DI to manage the components that make up an application. These objects are called Spring Beans, which we will discuss in the next chapter.
容器通过读取提供的配置元数据来获取有关实例化、配置和组装对象的指令。该配置元数据可由 XML、Java 注释或 Java 代码表示。下图展示了 Spring 的工作原理的概述图。Spring IOC 容器利用 Java POJO 类和配置元数据来生成完全配置和可执行的系统或应用程序。
The container gets its instructions on what objects to instantiate, configure, and assemble by reading the configuration metadata provided. The configuration metadata can be represented either by XML, Java annotations, or Java code. The following diagram represents a high-level view of how Spring works. The Spring IoC container makes use of Java POJO classes and configuration metadata to produce a fully configured and executable system or application.
Spring 提供了下列两种不同类型的容器。
Spring provides the following two distinct types of containers.
Sr.No. |
Container & Description |
1 |
Spring BeanFactory ContainerThis 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 ContainerThis 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。
The ApplicationContext container includes all functionality of the BeanFactorycontainer, so it is generally recommended over BeanFactory. BeanFactory can still be used for lightweight applications like mobile devices or applet-based applications where data volume and speed is significant.