1.1. Introduction to the Spring IoC Container and Beans

本文深入探讨了Spring框架如何实现Inversion of Control(IoC)原则,也就是依赖注入(DI)。Spring的BeanFactory和ApplicationContext是IoC容器的基础,负责对象的实例化、装配和依赖管理。BeanFactory提供基本配置,而ApplicationContext则添加了如AOP整合、消息资源处理、事件发布等功能。Spring中的bean是应用的核心组件,由IoC容器管理其生命周期和依赖关系。

This chapter covers the Spring Framework implementation of the Inversion of Control (IoC) principle. (See Inversion of Control.)

这一章节介绍Spring框架关于IoC的实现

IoC is also known as dependency injection (DI).

IoC也称为依赖注入(DI) 译者注: 感觉通过依赖注入的方式实现IoC更加贴切

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.

IoC是一个对象定义他们依赖项的过程, 在此过程中, 对象只需在它的依赖项被构造完成, 或者从工厂方法返回出来之后, 通过构造函数的参数, 工厂方法的参数, 或者对象的自己的属性, 就能够进行定义它的依赖项.

The container then injects those dependencies when it creates the bean.

然后, 容器在创建该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.

这个过程从根本上讲, 是使用类直接构造, 或者类似服务定位器这种控件生成依赖的逆过程

The org.springframework.beans and org.springframework.context packages are the basis for Spring Framework’s IoC container.

这两个包是Spring框架IoC容器的基础

The BeanFactory interface provides an advanced configuration mechanism capable of managing any type of object.

BeanFactory接口提供了一种高级配置机制, 能够管理任何类型的对象

ApplicationContext is a sub-interface of BeanFactory . It adds:

ApplicationContext是BeanFactory的子接口, 它增加了:

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

  • 特定的用于应用程序层次的上下文, 比如WebApplicationContext

In short, the BeanFactory provides the configuration framework and basic functionality, and the ApplicationContext adds more enterprise-specific functionality.

简而言之, BeanFactory提供了对框架的配置和一些基础功能, ApplicationContext添加了更多的企业开发特定的功能

The ApplicationContext is a complete superset of the BeanFactory and is used exclusively in this chapter in descriptions of Spring’s IoC container.

ApplicationContext是一个BeanFactory的完全的超集, 而且在本章节中专门用来相容Spring的IoC容器

For more information on using the BeanFactory instead of the ApplicationContext, see 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.

在Spring中, 那些构成你应用的主干, 并且被Spring IoC管理的对象, 被称为Beans

A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container.

Bean是由Spring IoC容器初始化, 装配, 和以其它方式进行管理的对象

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.

所有Bean对象, 以及它们依赖的对象, 都被映射在容器所使用的配置元数据中

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值