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.
接口ApplicationContext表示spring容器,并负责实例化、配置、组装beans。容器通过读取配置元数据来获取那些需要实例化、配置、组装的对象信息。配置元数据可以使用xml、java注解,java代码表示。
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的几个开箱即用的实现。在单独的应用中通常会创建一个ClassPathXmlApplicationContext或FileSystemXmlApplicationContext的实例。虽然xml是配置元数据的传统格式,但你也可以通过少量的xml配置来声明支持使用java注解或代码作为配置元数据。
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容器。例如在web应用中,web.xml文件中简单的8行左右描述信息就足够了
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工作的原理图,类和配置数据组合在一起,当ApplicationContext创建和实例化后,你就拥有一个可执行的应用及其完整的配置

浙公网安备 33010602011771号