SpringCloud升级之路2020.0.x版-5.所有项目的parent与spring-framework-common说明

本系列代码地址:https://github.com/HashZhang/spring-cloud-scaffold/tree/master/spring-cloud-iiford

源代码文件:https://github.com/HashZhang/spring-cloud-scaffold/blob/master/spring-cloud-iiford/pom.xml
1. 使用 log4j2 异步日志所需要的依赖:需要排除默认的日志实现 logback,增加 log4j2 的依赖,并且添加 log4j2 异步日志需要的 disruptor 依赖。
<!--日志需要用log4j2-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
<!--log4j2异步日志需要的依赖,所有项目都必须用log4j2和异步日志配置-->
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>${disruptor.version}</version>
</dependency>
2. javax.xml 的相关依赖。我们的项目使用 JDK 11。JDK 9 之后的模块化特性导致 javax.xml 不自动加载,所以需要如下模块:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>${jaxb.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>${jaxb.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId>
<version>${jaxb.version}</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>${activation.version}</version>
</dependency>
3. 使用 Junit 5 进行单元测试,Junit 5 使用可以参考:Junit5 user guide
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
4. 使用 Spring Boot 单元测试,可以参考:features.testing
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
5. mockito扩展,主要是需要mock final类:Spring Boot 单元测试已经包含了 mockito 依赖了,但是我们还需要 Mock final 类,所以添加以下依赖:
<!--mockito扩展,主要是需要mock final类-->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mokito.version}</version>
<scope>test</scope>
</dependency>
6. embedded-redis:使用 embedded-redis 用于涉及 Redis 的单元测试:如果你的单元测试需要访问 redis,则需要在测试前初始化一个 redis,并在测试后关闭。使用 embedded-redis 就可以。我们在 spring-cloud-parent 中已经添加了这个依赖,所以可以直接使用。参考:embedded-redis
<dependency>
<groupId>com.github.kstyrc</groupId>
<artifactId>embedded-redis</artifactId>
<version>${embedded-redis.version}</version>
<scope>test</scope>
</dependency>
7. sqlite 单元测试依赖:对于数据库的单元测试,我们可以使用 SQLite。参考:sqlite-jdbc
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>${sqlite-jdbc.version}</version>
<scope>test</scope>
</dependency>
8. 指定编译级别为 Java 11
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>11</source>
<!--ingore javac compiler assert error-->
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>

作为使用 spring 与 spring boot 框架的公共依赖 spring-framework-common 项目是一个纯依赖的项目。
1. 内部缓存框架统一采用caffeine:这是一个很高效的本地缓存框架,接口设计与 Guava-Cache 完全一致,可以很容易地升级。性能上,caffeine 源码里面就有和 Guava-Cache, ConcurrentHashMap,ElasticSearchMap,Collision 和 Ehcache 等等实现的对比测试,并且测试给予了 yahoo 测试库,模拟了近似于真实用户场景,并且,caffeine 参考了很多论文实现不同场景适用的缓存,例如:
- Adaptive Replacement Cache:http://www.cs.cmu.edu/~15-440/READINGS/megiddo-computer2004.pdf
2.Quadruply-segmented LRU:http://www.cs.cornell.edu/~qhuang/papers/sosp_fbanalysis.pdf - 2 Queue:http://www.tedunangst.com/flak/post/2Q-buffer-cache-algorithm
- Segmented LRU:http://www.is.kyusan-u.ac.jp/~chengk/pub/papers/compsac00_A07-07.pdf
- Filtering-based Buffer Cache:http://storageconference.us/2017/Papers/FilteringBasedBufferCacheAlgorithm.pdf
所以,我们选择 caffeine 作为我们的本地缓存框架,参考:caffeine
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>
2. 使用 google 的 java 开发库 guava:guava 是 google 的 Java 库,虽然本地缓存我们不使用 guava,但是 guava 还有很多其他的元素我们经常用到。参考:guava docs
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
3. 内部序列化统一采用fastjson:注意 json 库一般都需要预热一下,后面会提到怎么做。参考:fastjson
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
</dependency>
4. 使用 lombok 简化代码,参考:projectlombok
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
5. 调用路径记录 - sleuth。参考:spring-cloud-sleuth
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-sleuth</artifactId>
</dependency>
6. 跨线程 ThreadLocal。参考:transmittable-thread-local
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>transmittable-thread-local</artifactId>
<version>${transmittable-thread-local.version}</version>
</dependency>
7. Swagger 相关。参考:swagger
<!--Swagger-->
<!-- swagger java元数据集成 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${swagger.version}</version>
</dependency>
<!-- swagger 前端页面 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${swagger.version}</version>
</dependency>
8. Apache Commons 相关工具包。我们会使用一些 Commons 工具包,来简化代码:
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>${commons-collections4.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-text -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>${commons-text.version}</version>
</dependency>

本小节我们详细说明了我们所有项目的 parent,以及 使用了 Spring 与 Spring Boot 特性的工具包依赖 spring-framework-common 的设计。下一节我们将详细分析提供微服务特性的依赖。
微信搜索“我的编程喵”关注公众号,每日一刷,轻松提升技术,斩获各种offer:

SpringCloud升级之路2020.0.x版-5.所有项目的parent与spring-framework-common说明的更多相关文章
- SpringCloud升级之路2020.0.x版-9.如何理解并定制一个Spring Cloud组件
本系列为之前系列的整理重启版,随着项目的发展以及项目中的使用,之前系列里面很多东西发生了变化,并且还有一些东西之前系列并没有提到,所以重启这个系列重新整理下,欢迎各位留言交流,谢谢!~ 我们实现的 S ...
- SpringCloud升级之路2020.0.x版-4.maven依赖回顾以及项目框架结构
本系列代码地址:https://github.com/HashZhang/spring-cloud-scaffold/tree/master/spring-cloud-iiford 我们先来回顾下 m ...
- SpringCloud升级之路2020.0.x版-1.背景
本系列为之前系列的整理重启版,随着项目的发展以及项目中的使用,之前系列里面很多东西发生了变化,并且还有一些东西之前系列并没有提到,所以重启这个系列重新整理下,欢迎各位留言交流,谢谢!~ Spring ...
- SpringCloud升级之路2020.0.x版-41. SpringCloudGateway 基本流程讲解(1)
本系列代码地址:https://github.com/JoJoTec/spring-cloud-parent 接下来,将进入我们升级之路的又一大模块,即网关模块.网关模块我们废弃了已经进入维护状态的 ...
- SpringCloud升级之路2020.0.x版-6.微服务特性相关的依赖说明
本系列代码地址:https://github.com/HashZhang/spring-cloud-scaffold/tree/master/spring-cloud-iiford spring-cl ...
- SpringCloud升级之路2020.0.x版-10.使用Log4j2以及一些核心配置
本系列代码地址:https://github.com/HashZhang/spring-cloud-scaffold/tree/master/spring-cloud-iiford 我们使用 Log4 ...
- SpringCloud升级之路2020.0.x版-43.为何 SpringCloudGateway 中会有链路信息丢失
本系列代码地址:https://github.com/JoJoTec/spring-cloud-parent 在开始编写我们自己的日志 Filter 之前,还有一个问题我想在这里和大家分享,即在 Sp ...
- SpringCloud升级之路2020.0.x版-29.Spring Cloud OpenFeign 的解析(1)
本系列代码地址:https://github.com/JoJoTec/spring-cloud-parent 在使用云原生的很多微服务中,比较小规模的可能直接依靠云服务中的负载均衡器进行内部域名与服务 ...
- SpringCloud升级之路2020.0.x版-34.验证重试配置正确性(1)
本系列代码地址:https://github.com/JoJoTec/spring-cloud-parent 在前面一节,我们利用 resilience4j 粘合了 OpenFeign 实现了断路器. ...
随机推荐
- C#构造函数中:this()的作用
通俗来说,可以说是构造函数的继承 (1) :this()用来继承无参时的构造函数,例如下面代码 static void Main(string[] args) { AA aA = new AA(&qu ...
- Mysql优化(出自官方文档) - 第二篇
Mysql优化(出自官方文档) - 第二篇 目录 Mysql优化(出自官方文档) - 第二篇 1 关于Nested Loop Join的相关知识 1.1 相关概念和算法 1.2 一些优化 1 关于Ne ...
- C、C++、python、Java、php、C#六种编程语言大PK 哪个好学习?
作为程序员吃饭的工具,编程语言之间也形成了某种鄙视链,各大论坛里弥漫着剑拔弩张的气氛,众口难调.也难怪有很多初学者会有疑惑,为什么会有这么多编程语言,我到底应该学什么语言? 其实各种语言都各有千秋.接 ...
- POJ 1775 Sum of Factorials 数论,基础题
输入一个小于1000000的正整数,是否能表达成式子:a1!+a2!+a3!+...+an (a1~an互不相等). 因为10!>1000000,所以先打1~10的阶乘表.从a[10]开始递减判 ...
- Cygwin-OpenSSH配置手册及常见问题解决
右键管理员方式运行Cygwin-setup-x86_64.exe 选择Install from Local Ddirectory 选择安装路径(默认下一步) 选择依赖库路径 依次配置一下选项 接下来安 ...
- C++智能指针之shared_ptr与右值引用(详细)
1. 介绍 在 C++ 中没有垃圾回收机制,必须自己释放分配的内存,否则就会造成内存泄露.解决这个问题最有效的方法是使用智能指针(smart pointer).智能指针是存储指向动态分配(堆)对象指针 ...
- MyEclipse中,编写properties文件,输入中文显示乱码
我在properties文件中输出中文,结果显示的是乱码,额......好吧,其实不是乱码,哪有这么规范的乱码 其实是在输入中文时发生了转码,就是下面这个样子: 字符集不支持中文,修改方法: 选中你工 ...
- linux学习之路第九天(任务调度)
crond 任务调度 概念 任务调度:是指的系统在某个时间执行的特定命令或程序. 比喻理解: 可以这样理解,比如生活中有闹钟,闹钟的作用是不是叫人起床的,那古时候没有闹钟,叫人起床的工作是不是要人去完 ...
- 如何用jmeter监控内存,CPU(1)
要jmeter的运行环境配置好就可以: 打开这个小工具的步骤很简单,如果你已经配置好了Jmeter运行的环境,那么你也就不用去做其他的配置,直接 点击:开始-->运行-->输入cmd--& ...
- 全彩LED灯
1.全彩 LED 灯,实质上是一种把红.绿.蓝单色发光体集成到小面积区域中的 LED 灯,控制时对这三种颜色的灯管输出不同的光照强度,即可混合得到不同的颜色,其混色原理与光的三原色混合原理一致.例如, ...