程序员英语学习
2022-7-25
核心技术
Version 5.3.22 瞎翻译的,自己学习,等以后成了大佬,依据自己的理解,再翻译一遍,期待。
This part of the reference documentation covers all the technologies that are absolutely integral to the Spring Framework.
参考文档这一部分覆盖了Spring框架的重要技术
reference :参考、提及、查阅
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容器,全面介绍完IOC容器之后,我们将会全面介绍AOP技术,Spring框架拥有自己的AOP框架,它成功解决了80%Java企业中的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与Aspect(当前在功能方面最全面、当前在Java企业中最成熟的应用)的集成
1. IOC容器
This chapter covers Spring’s Inversion of Control (IoC) container.
本章涵盖了IOC容器部分
1.1 Spring IOC 与 Bean的介绍
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也被称为依赖注入。这是一个过程,对象仅通过构造函数参数、工厂方法的参数或在对象实例被构造或从工厂方法返回后设置的属性来定义它们的依赖关系(即与它们一起工作的其他对象)。然后容器在创建 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:
org.springframework.beans
和 org.springframework.context
包是IOC容器的基础包,Bean工厂接口提供了一个高级够管理任何类型对象的机制的配置。ApplicationContext上下文参数,是一个Bean工厂的子接口,它增加了:
- Easier integration with Spring’s AOP features
- 更容易与Spring AOP功能集成
- Message resource handling (for use in internationalization)
- 消息资源处理(用于国际化)
- Event publication
- 事件发布
- Application-layer specific contexts such as the
WebApplicationContext
for use in web applications. - 应用层特定上下文,例如用于 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,
see the section covering the BeanFactory
API.
简而言之,BeanFactory提供一个基础功能的配置框架,ApplicationContext增加了更多企业特定的功能,ApplicationContext是BeanFactory的完整超集,在本章中专门用于描述Spring的IoC容器。有关使用BeanFactory而不是ApplicationContext的信息,详见链接BeanFactory
API.。
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 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是实例化、装配并被IoC容器管理,否则,bean只是应用程序中许多对象中的一个。bean以及它们之间的依赖关系反映在容器使用的配置元数据中。
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接口代表了IOC容器,负责实例化、配置和组装bean。容器通过读取配置的元数据获取关于对象实例化、配置、装配的指令。配置元数据代表的类型有XML、注解、JavaConfig。它允许表达组成项目的对象以及对象之间丰富的依赖关系。
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应用程序的场景中,简单的8行Web描述符xml通常就够了(参考web应用程序便捷的Application实例化)。如果你使用Eclipse(Eclipse的开发环境)的Spring工具,你可以通过简单的鼠标点击或者击键创建一个配置模板。
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创建及实例化后,你便拥有了一个完整配置、可执行的系统或程序。
本文来自博客园,作者:帅气的涛啊,转载请注明原文链接:https://www.cnblogs.com/handsometaoa/p/16473594.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了