转载

Spring Framework 5.2.2 文档中文翻译版之IOC容器与Bean简介

特别说明

这是一个由simviso团队所组织进行的基于Spring Framework 5.2.2版本基础文档翻译。如果想要深入讨论,可扫描下方二维码,加入官方群和知秋的知识星球,免费给大家分享相关知识。

由于专业文档翻译难度比较大,我们内部本着翻译质量,也有一系列的规范,也因这些规范,消耗的时间更多,同时我们自己时间也是有限的,作为公益组织,当下也没什么收益,都是小伙伴每天晚上熬夜在做事情,请勿催更,望理解。

本节参与人员

知秋-掘金博客

https://juejin.im/user/59c764...

虚生花-掘金博客

https://juejin.im/user/5c52b6...

Spring Framework 5.2.2 文档中文翻译版之IOC容器与Bean简介

核心技术(Core Technologies)

This part of the reference documentation covers all the technologies that are absolutely integral to the Spring Framework.

参考文档的这一部分涵盖了Spring框架中所有必不可少的技术。

Foremost amongst these is the Spring Framework’s Inversion of Control (IoC) container. A thorough treatment of the Spring Framework’s IoC container is closely followed by comprehensive coverage of Spring’s Aspect-Oriented Programming (AOP) technologies. The Spring Framework has its own AOP framework, which is conceptually easy to understand and which successfully addresses the 80% sweet spot of AOP requirements in Java enterprise programming.

其中最重要的就是Spring框架中的IoC容器。当对Spring IoC容器充分理解后,紧随其来的就是对Spring AOP(面向切面编程)相关的全面介绍。Spring框架拥有它自己的AOP框架,该框架从概念上易于理解,它成功解决了Java企业编程中80%AOP需求相关痛点。

Coverage of Spring’s integration with AspectJ (currently the richest — in terms of features — and certainly most mature AOP implementation in the Java enterprise space) is also provided.

其中也涵盖了Spring与AspectJ的集成(就功能而言,目前它是最丰富也是Java企业领域中最成熟的AOP实现)。

IoC容器

This chapter covers Spring’s Inversion of Control (IoC) container.

本章节涵盖了Spring IoC容器相关内容。

Spring IoC容器与Bean简介(Introduction to the Spring IoC Container and Beans)

This chapter covers the Spring Framework implementation of the Inversion of Control (IoC) 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) 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.

本章节涵盖了Spring框架对于控制反转(IoC)原理的实现。IoC也被称为依赖注入(DI) 。在此过程中,对象只能通过构造函数参数,工厂方法的参数来定义其依赖项(即与之一起使用的其他对象),或者在通过构造器构造或从工厂方法返回得到对象实例之后,在对象实例上对其属性进行设置。然后,容器在创建bean时注入那些依赖项。此过程从本质上来讲是通过使用类的直接构造或者例如服务定位模式之类的机制,从根本上反转了bean自身对它依赖项的定位(知秋注:和其他bean建立依赖联系)或实例化(因此称为控制反转)。

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:

WebApplicationContext

org.springframework.beansorg.springframework.context 两个包是Spring框架中IoC容器的基础。 BeanFactory 接口提供了一种能够管理任何类型对象的高级配置机制。 ApplicationContextBeanFactory 的子接口,它添加了以下特性:

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, see [beans-beanfactory].

简单来说, BeanFactory 提供了配置框架以及基础功能,而 ApplicationContext 添加了更多企业特定的功能。 ApplicationContextBeanFactory 的一个完整超集,它在本章中只用来描述Spring IoC容器。如果想了解更多 BeanFactory 使用上的信息而不是 ApplicationContext 的话,请查看 [beans-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 IoC容器进行管理的对象被称为bean。bean是一个由Spring IoC容器实例化,组装并管理的一个对象。否则的话,bean只是你应用中众多对象中的一个而已。Bean及其之间的依赖关系都反映在容器使用的配置元数据中。

原文  https://segmentfault.com/a/1190000021573163
正文到此结束
Loading...