Spring Framework Analysis


Spring framework three core components:

  • Core
  • Context
  • Beans

They built up a whole Spring of bone architecture.

Spring design

Bean Object as the significance of OOP in the same role in the Spring, there is no concept of the object is no object-oriented programming. Spring the dependencies between objects instead use the configuration file to manage, that is, his dependency injection mechanism. And this relationship is injected at a place called IOC container management, the IOC container is to be wrapped objects Bean, Spring integer objects reported by Bean installed in the management of these to achieve the objects and purposes out a series of operations.

IOC

IOC stands (Inversion of Control) control inversion, one design principles of object oriented programming, can be used to reduce the degree of coupling between the computer code.

For spring framework, it is the relationship between the spring be responsible for controlling the lifetime of the object and the object. Traditionally the right call by the program code to direct manipulation of the object container, to achieve the object management component assembly and through the container. The so-called "inversion of control" that is, the transfer of control of the Component Object, transferred from the program code itself to the outside of the container, the container to create objects and manage dependencies between objects.

IoC is the system is running, the dynamic it needs to provide other objects to an object. This dependency injection (DI) to achieve.

OF

DI-Dependency Injection, namely "dependency injection": is the dependencies between components at runtime is determined by the vessel, said the image that dynamically inject the dependencies into a container assembly. Dependency injection is not intended to bring more functionality to the software system.

When an object is simply to call other objects, the object of this work is called handed spring to complete, and inject dependencies. Dependence here refers to dependencies between Bean and container.

1
When a role requires the assistance of another role when, in the traditional program design process, usually to create an instance of the caller by the caller. But creation is the work of the caller is no longer done by the caller in the spring, so called inversion of control. Create a callee work done by the spring, and then injected into the caller. It is also known dependency injection.

The relationship between the IOC and DI

其实它们是同一个概念的不同角度描述,由于控制反转概念比较含糊(可能只是理解为容器控制对象这一个层面,很难让人想到谁来维护对象关系),所以2004年大师级人物Martin Fowler又给出了一个新的名字:“依赖注入”。相对IoC 而言,“依赖注入”明确描述了“被注入对象依赖IoC容器配置依赖对象”。

核心组件 协同工作

Context 就是一个 Bean 关系的集合,这个关系集合又叫 Ioc 容器。Core 就是发现、建立和维护每个 Bean 之间的关系所需要的一些列的工具。

Bean 组件

Bean 组件在 Spring 的 org.springframework.beans 包下。这个包下的所有类主要解决了三件事:

  • Bean的定义
  • Bean的创建
  • Bean的解析

对 Spring 的使用者来说唯一需要关心的是 Bean 的创建,其余的由 Spring 在内部帮你完成。

Context组件

Context 在 Spring 的 org.springframework.context 包下, Context 组件实际上就是给 Spring 提供一个运行时的环境,用以保存各个对象的状态。

ApplicationContext 是 Context 的顶级父类,他除了能标识一个应用环境的基本信息外,他还继承了五个接口,这五个接口主要是扩展了 Context 的功能。

总体来说 ApplicationContext 必须要完成以下几件事:

  • 标识一个应用环境
  • 利用 BeanFactory 创建 Bean 对象
  • 保存对象关系表
  • 能够捕获各种事件

    Context 作为 Spring 的 Ioc 容器,基本上整合了 Spring 的大部分功能,或者说是大部分功能的基础。

Core组件

Core 组件作为 Spring 的核心组件,他其中包含了很多的关键类,其中一个重要组成部分就是定义了资源的访问方式。把所有资源都抽象成一个接口。

AOP(面向切面编程)

面向切面编程(AOP是Aspect Oriented Program的首字母缩写) ,我们知道,面向对象的特点是继承、多态和封装。而封装就要求将功能分散到不同的对象中去,这在软件设计中往往称为职责分配。实际上也就是说,让不同的类设计不同的方法。这样代码就分散到一个个的类中去了。这样做的好处是降低了代码的复杂程度,使类可重用。 这种在运行时,动态地将代码切入到类的指定方法、指定位置上的编程思想就是面向切面的编程。

一般而言,我们管切入到指定类指定方法的代码片段称为切面,而切入到哪些类、哪些方法则叫切入点。有了AOP,我们就可以把几个类共有的代码,抽取到一个切片中,等到需要时再切入对象中去,从而改变其原有的行为。这样看来,AOP其实只是OOP的补充而已。OOP从横向上区分出一个个的类来,而AOP则从纵向上向对象中加入特定的代码。有了AOP,OOP变得立体了。如果加上时间维度,AOP使OOP由原来的二维变为三维了,由平面变成立体了。从技术上来说,AOP基本上是通过代理机制实现的。

原文:大专栏  Spring 框架分析


Guess you like

Origin www.cnblogs.com/sanxiandoupi/p/11652346.html