Spring Framework Documentation (5.3.10)
Core | IoC Container, Events, Resources, i18n, Validation, Data Binding, Type Conversion, SpEL, AOP. |
1. The IoC Container
1.1. Introduction to the Spring IoC Container and Beans(Spring IoC容器和bean简介)
1.2. Container Overview (容器概览)
1.2.1. Configuration Metadata (配置元数据)
1.2.2. Instantiating a Container(实例化一个容器)
1.2.2.1 Composing XML-based Configuration Metadata(组合基于XML的配置元数据)
1.2.2.2 The Groovy Bean Definition DSL (Groovy Bean定义DSL)
1.2.3. Using the Container (使用容器)
下载此文档精编完整版
No. | 内容 | 下载地址 | 文档内容目录 |
1 | 中英双语精编版 第一部分 | PDF下载 | 内容目录 |
2 | 中英双语精编版 第二部分 | PDF下载 | 内容目录 |
3 | 中文精编版 第一部分 | PDF下载 | 内容目录 |
4 | 中文精编版 第二部分 | PDF下载 | 内容目录 |
更多章节内容,请点击查看: Core Technologies
1.2. Container Overview 容器概览
The org.springframework.context.ApplicationContext interface represents the Spring IoC container and is responsible for instantiating, configuring, and assembling the beans. The container gets its instructions on what objects to instantiate, configure, and assemble by reading configuration metadata. The configuration metadata is represented in XML, Java annotations, or Java code. It lets you express the objects that compose your application and the rich interdependencies between those objects.
org.springframework.context.ApplicationContext接口表示Spring IoC容器,负责实例化、配置和组装(instantiating, configuring, and assembling)bean。容器通过读取配置元数据(configuration metadata)获取关于实例化、配置和所组装对象的指令。配置元数据(configuration metadata)以XML、Java注解或Java代码(XML, Java annotations, or Java code)表示。它允许您表示组成应用程序的对象以及这些对象之间丰富的相互依赖关系(interdependencies)。
Several implementations of the ApplicationContext interface are supplied with Spring. In stand-alone applications, it is common to create an instance of ClassPathXmlApplicationContext or FileSystemXmlApplicationContext. While XML has been the traditional format for defining configuration metadata, you can instruct the container to use Java annotations or code as the metadata format by providing a small amount of XML configuration to declaratively enable support for these additional metadata formats.
Spring提供了ApplicationContext 接口的几种实现。在独立应用程序(stand-alone application)中,通常创建ClassPathXmlApplicationContext 或FileSystemXmlApplicationContext的实例。虽然XML一直是定义配置元数据的传统格式,但您可以通过提供少量XML配置以声明对其他元数据格式提供支持,从而指示容器采用Java注解或代Java码作为另外的元数据格式(metadata format)。
In most application scenarios, explicit user code is not required to instantiate one or more instances of a Spring IoC container. For example, in a web application scenario, a simple eight (or so) lines of boilerplate web descriptor XML in the web.xml file of the application typically suffices (see Convenient ApplicationContext Instantiation for Web Applications). If you use the Spring Tools for Eclipse (an Eclipse-powered development environment), you can easily create this boilerplate configuration with a few mouse clicks or keystrokes.
在大多数应用场景中,不需要显式的用户代码来实例化Spring IoC容器的一个或多个实例。例如,在web应用程序场景中,应用程序的web.xml文件中的一个简单的八行(大约八行)样板web描述符XML通常就足够了(请参见Convenient ApplicationContext Instantiation for Web Applications)。如果您使用Spring Tools for Eclipse(一个支持Eclipse的开发环境),只需点击几下鼠标或按键,就可以轻松创建这个样板配置。
The following diagram shows a high-level view of how Spring works. Your application classes are combined with configuration metadata so that, after the ApplicationContext is created and initialized, you have a fully configured and executable system or application.
下图是展示Spring如何工作的高级视图。您的应用程序类(application class)与配置元数据(configuration metadata)相结合,以便在创建和初始化ApplicationContext 后,您拥有一个完全配置且可执行的系统或应用程序。
Figure 1. The Spring IoC container
图1. Spring IoC容器