首页 > 技术文章 > 01.Spring文档之Spring概述

Ishton 2021-10-11 03:10 原文

1 Spring 框架概述

Spring 使创建 Java 企业应用程序变得容易。它提供了在企业环境中使用 Java 语言所需的一切,支持 Groovy 和 Kotlin 作为 JVM 上的替代语言,并且可以根据应用程序的需要灵活地创建多种架构。

Spring指的是什么意思?

what we mean by "Spring"?

The term "Spring" means different things in different contexts. It can be used to refer to the Spring Framework project itself, which is where it all started. Over time, other Spring projects have been built on top of the Spring Framework. Most often, when people say "Spring", they mean the entire family of projects.

术语“Spring”在不同的上下文中意味着不同的东西。它可以用来指代 Spring Framework 项目本身,这就是一切的开始。随着时间的推移,其他 Spring 项目已经构建在 Spring 框架之上。大多数情况下,当人们说“春天”时,他们指的是整个项目系列。

The Spring Framework is divided into modules. Applications can choose which modules they need. At the heart are the modules of the core container, including a configuration model and a dependency injection mechanism.

Spring 框架分为多个模块。应用程序可以选择他们需要的模块。核心是核心容器的模块,包括配置模型和依赖注入机制。

2 The IoC Container

2.1. Spring IoC Container 和 Bean 介绍

Introduction to the Spring IoC Container and Beans

IoC原理

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本身通过直接构造类或Service Locator模式等机制来控制依赖项的实例化或位置的相反过程(因此得名“控制倒置”)。

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.

org.springframework.beans和org.springframework.context包是Spring框架的IoC容器的基础。 BeanFactory 接口提供了一种能够管理任何类型对象的高级配置机制。 ApplicationContext 是BeanFactory的子接口。

Bean介绍

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 是由 Spring IoC 容器实例化、组装和管理的对象。否则,bean 只是应用程序中众多对象之一。Bean 以及它们之间的依赖关系反映在容器使用的配置元数据中。

推荐阅读