Spring 笔记(二)模块体系

前言

在 Spring Boot 出现之前,开发一个 Spring 项目总会需要添加很多依赖。但是我们在配置依赖的时候,往往不太明确各依赖的具体作用,经常是从网上复制粘贴。
为何需要添加这些依赖?各依赖之间有何关系?某个依赖是否可以省略?要回答这些问题,就有必要了解 Spring 的依赖体系。

搞清了这些问题后,下次配置依赖时,就能很清楚的知道自己需要添加哪些依赖了。

Spring Framwork Modules

这里仅针对 Spring 4 和 Spring 5

Spring 框架被分解成 20 个左右的模块,这些模块又按功能分成多个类别:
Overview of the Spring Framework

Core Container

核心容器由 spring-core, spring-beans, spring-context, spring-context-support, 和 spring-expression 组成

spring-core 和 spring-beans

spring-core 和 spring-beans 是 Spring 的基石,提供了基本的 DI 功能。
但是我们基本不需要添加这两个依赖,因为我们通常都会使用更上层的模块,而这些上层模块依赖了它们,我们引入上层模块后,依赖管理工具会自动链入下层依赖。

spring-expression

spring-expression 定义了强大的 Spring 表达式语言,用于在运行时查询和操作对象。

spring-context 和 spring-context-support

spring-context 建立在 core 和 beans 之上,提供了更高层的 API。其核心是 ApplicationContext。
spring-context-support 则是为将第三方库整合进 Spring 应用上下文 提供支持。

普通的 Spring 应用只需要引入 spring-context 模块:

implementation group: 'org.springframework', name: 'spring-context', version: '5.0.7.RELEASE'

从上面的依赖关系图就能知道,四个核心模块都是它的依赖。

AOP 和 Instrumentation

这一部分包含下列模块:spring-aop, spring-aspects, spring-instrument, spring-instrument-tomcat

spring-aop 提供了面向切面编程的实现,它允许你定义拦截器 (interceptors) 和 切点 (pointcuts),用以解耦(decouple) 关注点不同的代码。
spring-aspects 整合了 Java 最强大的一个 AOP 库:AspectJ.
spring-instrument 提供了用于某些应用程序服务器的类工具支持和类加载器实现.
spring-instrument-tomcat 是 Spring’s instrumentation agent for Tomcat.

其他的见参考。。懒啊

参考

猜你喜欢

转载自www.cnblogs.com/kirito-c/p/9198297.html