跳到主要内容

Spring5中文文档【2】Spring核心之IOC容器和Bean简介

1. IOC容器和Bean简介

本系列基于最新5.3.10版本,大部分内容copy于官方文档…
官方文档地址

1.1 IOC是什么?

IOC是Inversion of Control的缩写,翻译过来就是控制反转,不是什么技术,而是一种设计思想。

早在1988,Ralph E. Johnson与BrianFoote在文章Designing Reusable Classes中有一段话,成为控制反转(Inversion of Control)的来由。

One important characteristic of a framework is that the methods defined by the user to tailor the framework will often be called from within the framework itself, rather than from the user's application code. The framework often plays the role of the main program in coordinating and sequencing application activity. This inversion of control gives frameworks the power to serve as extensible skeletons. The methods supplied by the user tailor the generic algorithms defined in the framework for a particular application.【框架/framework的一个重要特征是,为定制框架而由用户定义的方法,常常由框架自己调用,而非由用户的应用程序代码(来调用)。在协调和理顺应用程序活动上,框架通常扮演主程序的角色。这种控制的反转给予框架这样的威力——作为一个可扩展的骨架。由用户提供的方法,将框架中定义的一般性算法加以定制给特定的应用。】

理解好Ioc的关键是要明确“谁控制谁,控制什么,为何是反转(有反转就应该有正转了),哪些方面反转了”,那我们来深入分析一下: