1.1 Spring IOC容器和Beans介绍

官方英文版地址:https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/core.html

备注:翻译如有不对,请多指正,谢谢。

1.1. Introduction to the Spring IoC container and beans

This chapter covers the Spring Framework implementation of the Inversion of Control (IoC) [1] principle. IoC is also known as dependency injection (DI). It is a process whereby objects define their dependencies, that is, the other objects they work with, only through constructor arguments, arguments to a factory method, or properties that are set on the object instance after it is constructed or returned from a factory method. The container then injects those dependencies when it creates the bean. This process is fundamentally the inverse, hence the name Inversion of Control (IoC), of the bean itself controlling the instantiation or location of its dependencies by using direct construction of classes, or a mechanism such as the Service Locator pattern.

本章将介绍控制反转(IoC)的Spring框架实现。IoC也被认为是依赖注入。它是一个定义对象依赖关系的过程,与之工作的其他对象,往往通过构造参数、传递参数给工厂方法、或者属性设置来进行构造。当创建这些Spring Bean对象的时候,容器将会自动注入这些依赖关系。这个过程从根本上说是相反的,正如IoC的名称(控制反转)一样,通过类的构造函数或者服务定位器模式来控制依赖对象的实例化和定位。

The org.springframework.beans and org.springframework.context packages are the basis for Spring Framework’s IoC container. The BeanFactory interface provides an advanced configuration mechanism capable of managing any type of object. ApplicationContext is a sub-interface of BeanFactory. It adds easier integration with Spring’s AOP features; message resource handling (for use in internationalization), event publication; and application-layer specific contexts such as the WebApplicationContext for use in web applications.

org.springframework.beansorg.springframework.context包是Spring IoC容器的根本。BeanFactory接口提供了高级配置机制,能够管理任何类型的对象。ApplicationConext是BeanFactory的子接口。它添加了与Spring AOP更容易集成的特性,如消息资源处理(用于国际化)、事件发布以及应用程序层特定的上下文,例如Web应用程序的WebApplicationContext。

In short, the BeanFactory provides the configuration framework and basic functionality, and the ApplicationContext adds more enterprise-specific functionality. The ApplicationContext is a complete superset of the BeanFactory, and is used exclusively in this chapter in descriptions of Spring’s IoC container. For more information on using the BeanFactory instead of the ApplicationContext, refer to The BeanFactory.

简而言之,BeanFactory提供了配置框架和基本功能,而ApplicationContext添加了更多企业应用特定的功能。ApplicationContext是BeanFactory的一个完整超集。在本章中,用于介绍Spring IoC容器。如果想了解更多BeanFactory而不是ApplicationContext的更多信息,请参阅 The BeanFactory

In Spring, the objects that form the backbone of your application and that are managed by the Spring IoC container are called beans. A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container. Otherwise, a bean is simply one of many objects in your application. Beans, and the dependencies among them, are reflected in the configuration metadata used by a container.

在Spring中,那些构建应用程序主干并被Spring容器管理的对象称之为Beans。Bean是由Spring IoC容器初始化、装配和管理的对象。否则,Bean只是你应用程序中众多对象的一个。Bean及其之间的依赖关系反映在Spring容器的配置元数据中。

猜你喜欢

转载自blog.csdn.net/andamajing/article/details/81604088