Spring 5.0.8.RELEASE文档 Core1-1.2 容器概述

版权声明:mj1001001 https://blog.csdn.net/qq_42786889/article/details/81560622

The interface org.springframework.context.ApplicationContext represents the Spring IoC container and is responsible for instantiating, configuring, and assembling the aforementioned 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 allows you to express the objects that compose your application and the rich interdependencies between such objects.

ApplicationContext接口是Spring IoC容器的代表并且它负责实例化、配置、组装依赖beans。容器会通过读取配置文件从而获得对象的实例化、配置、组装依赖的指令从而为bean实例化。配置文件通常是xml文件、注解或者纯手动java代码的方式。配置允许你更好地表达beans在你所构建的应用中的各种相互依赖的关系。

Several implementations of the ApplicationContext interface are supplied out-of-the-box with Spring. In standalone 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.

ApplicationContext 接口的几个实现都提供开箱即用。一般独立的应用通常都是创建ClassPathXmlApplicationContext 或者FileSystemXmlApplicationContext的实例。xml是配置文件(配置各项配置元数据)的最传统的方式,当然你也可以使用Java注解或者纯手动Java代码的方式去控制容器来减少xml文件的配置量(去声明这些额外的元数据配置)(类似扫包注入而不用xml配置对象的实例化和依赖 -,-)

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 will typically suffice (see Convenient ApplicationContext instantiation for web applications). If you are using the Spring Tool Suite Eclipse-powered development environment this boilerplate configuration can be easily created with few mouse clicks or keystrokes.

在许多应用场景,不需要显式的用户的代码(手动new)去实例一个或者多个IoC容器。例如,在Web应用场景,简单的八行xml样板代码往web.xml上一放,这个Web应用就已经足够了。加入你是使用Spring Tool Suite这个IDE的话,上述的样板代码你只需要点几个鼠标键即可生成。

The following diagram is 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框架核心(IoC)的工作原理,你的应用class和配置元数据会进行组合(由Spring去干这事)以便于在ApplicationContext 创建后,你就会得到完全配置好并且可执行的系统或应用。
Spring IoC容器

猜你喜欢

转载自blog.csdn.net/qq_42786889/article/details/81560622