Spring Framework Documentation - core - 1. The IoC Container - 1.1对Spring IoC 和Bean的简明介绍

原文链接:https://docs.spring.io/spring-framework/docs/current/reference/html/core.html

spring version 5.3.9

本部分的参考文档包括了 Spring Framework 涉及的所有技术。

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

Spring Framework 中最重要的就是控制反转容器。在对Spring Framework的IoC 容器做一个全面的介绍之后,将综合介绍Spring的面向方面编程(AOP)技术。Spring框架有自己的AOP框架,在概念上很容易理解,它成功地解决了Java企业编程中80%的AOP需求。

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与AspectJ集成也会被提到,AspectJ是目前特性最丰富 ,在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.

1. IoC 容器The IoC Container

本章节包括了Spring 的控制反转容器。

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

1.1. 对Spring IoC 和Bean的简明介绍 Introduction to the Spring IoC Container and Beans

本章节会介绍IoC的原理,IoC 又被称作依赖注入 DI 。IoC的过程是对象不管他依赖的其他对象在哪里定义的,只有通过构造器参数,或者工厂方法的参数,或者是对象在构造方法,或者工厂方法完成实例化后, set 对应的属性。容器会在创建Bean的时候注入他们的依赖项。通常对象自身需要管理他依赖的实例,比如直接使用构造函数,或者使用 服务器定位模式 ,但是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.

org.springframework.beans 和org.springframework.context 包就是Spring Framework IoC容器的基础。BeanFactory 接口提供了先进的配置机制管理任何类型的对象。 ApplicationContext  是BeanFactory 的子接口,他新增功能有:

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:

  • 更简洁的集成Spring AOP 的特性

  • 国际化适用的消息资源处理

  • 事件发布

  • 应用层面的context 具体化,比如WebApplicationContext 用于web应用

  • Easier integration with Spring’s AOP features

  • Message resource handling (for use in internationalization)

  • Event publication

  • Application-layer specific contexts such as the WebApplicationContext for use in web applications.

简单来说, BeanFactory 提供的是配置框架和基础功能,AppliactionContext 增加了特定的企业级功能。对BeanFactory 来说,ApplicationContext  是一个完整的超集,在本章中专门用于描述IoC容器。更多参考 The BeanFactory.

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 BeanFactory.

在Spring 中,应用中的关键对象,并被Spring IoC容器管理,可被成为bean。bean 的实例化,装配,管理都交给了IoC容器。此外,bean 在你的应用中就是许多对象中普通的一个。这些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.

下一篇: 1.2容器总览

Version 5.3.9
Last updated 2021-07-14 06:36:18 UTC

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值