背景

公司的一个项目由于HTTPS证书到期,导致小程序、POS不能正常使用。所以百度了下,通过URL检测证书有效期的代码,并自行整合到一个服务中。

代码仓库:[基于SpringBoot + 企业微信 + 钉钉 的通知服务] (https://gitee.com/tec-cloud/tec-notice),由于码云的仓库策略调整,可能无法正常访问。

问题溯源

spring:
redis:
client-type: lettuce
host: 127.0.0.1
lettuce:
pool:
#最大连接数
max-active: 10
#连接池中最小空闲连接
min-idle: 2
#连接池中最大空闲连接
max-idle: 3
#最大建立连接等待时间。如果超过此时间将接到异常。设为-1表示无限制。
max-wait: 60s
#空闲链接检测线程检测周期毫秒(负值表示不检测)(类型为Duration,添加秒)
time-between-eviction-runs: 60s
#关闭超时时间
shutdown-timeout: 1s
port: 6379
password:
#连接超时时间毫秒(类型为Duration,添加秒)
timeout: 60s

以上是redis的配置,想将配置存储在redis中,所以通过lettuce集成spring-boot-starter-data-redis。

根据依赖传递spring-boot-starter-data-redis v2.7.0 --> lettuce-core v6.1.8.RELEASE --> commons-pool2 v2.9.0定位到依赖配置,如下:

    <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.9.0</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>

同时,我注意到optional=true,所以在项目根pom.xml添加本依赖,并移除optional。如下:

    <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.9.0</version>
<scope>compile</scope>
</dependency>

启动后,报错:

2022-06-12 16:32:17.716 ERROR 15092 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
*************************** Description: An attempt was made to call a method that does not exist. The attempt was made from the following location: org.springframework.boot.autoconfigure.data.redis.LettuceConnectionConfiguration$PoolBuilderFactory.getPoolConfig(LettuceConnectionConfiguration.java:185) The following method did not exist: org.apache.commons.pool2.impl.GenericObjectPoolConfig.setTimeBetweenEvictionRuns(Ljava/time/Duration;)V The calling method's class, org.springframework.boot.autoconfigure.data.redis.LettuceConnectionConfiguration$PoolBuilderFactory, was loaded from the following location: jar:file:/C:/Users/Administrator/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.7.0/spring-boot-autoconfigure-2.7.0.jar!/org/springframework/boot/autoconfigure/data/redis/LettuceConnectionConfiguration$PoolBuilderFactory.class The called method's class, org.apache.commons.pool2.impl.GenericObjectPoolConfig, is available from the following locations: jar:file:/C:/Users/Administrator/.m2/repository/org/apache/commons/commons-pool2/2.9.0/commons-pool2-2.9.0.jar!/org/apache/commons/pool2/impl/GenericObjectPoolConfig.class The called method's class hierarchy was loaded from the following locations: org.apache.commons.pool2.impl.GenericObjectPoolConfig: file:/C:/Users/Administrator/.m2/repository/org/apache/commons/commons-pool2/2.9.0/commons-pool2-2.9.0.jar
org.apache.commons.pool2.impl.BaseObjectPoolConfig: file:/C:/Users/Administrator/.m2/repository/org/apache/commons/commons-pool2/2.9.0/commons-pool2-2.9.0.jar
org.apache.commons.pool2.BaseObject: file:/C:/Users/Administrator/.m2/repository/org/apache/commons/commons-pool2/2.9.0/commons-pool2-2.9.0.jar Action: Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.boot.autoconfigure.data.redis.LettuceConnectionConfiguration$PoolBuilderFactory and org.apache.commons.pool2.impl.GenericObjectPoolConfig Disconnected from the target VM, address: '127.0.0.1:51044', transport: 'socket' Process finished with exit code 1

根据日志,确认错误:不存在GenericObjectPoolConfig.setTimeBetweenEvictionRuns方法,启动发生错误,终止并退出。

本着周末不学习就是退步的想法,跟踪了https://github.com/apache/commons-pool.githttps://github.com/spring-projects/spring-boot.git对应的版本、TAG及commit history。仅在spring-boot的提交记录中发现一点端倪。

如图:





不过提交时间是在spring-boot v2.7.x的初始化发布日期2022-05-19之前,参考:https://spring.io/projects/spring-boot#support

最终只要带着这个困惑,翻阅spring-boot、spring-data-redis的closed的Issue,结果被我搜个正着。

https://github.com/spring-projects/spring-data-redis/issues?q=is%3Aissue+is%3Aclosed+GenericObjectPoolConfig

根据其中的讨论,得到有效信息,依赖版本有冲突,删掉了2.9.0:The problem solved by deleting explicit dependency org.apache.commons:commons-pool2:2.9.0. Now it uses commpons-pool2:2.11.1

见链接:

https://github.com/spring-projects/spring-data-redis/issues/2293#issuecomment-1084310766

马不停蹄地开始试验:

        <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>

服务正常启动了。

解决方案

版本由spring-boot-dependencies来控制,直接读取<commons-pool2.version>2.11.1</commons-pool2.version>即可。当然也可以使用${commons-pool2.version}来明确定义版本。

        <dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>

【原创】SpringBoot 2.7.0通过lettuce及commons-pool2 v2.9.0集成Redis踩坑记录的更多相关文章

  1. SpringBoot + Shiro + shiro.ini 的踩坑记录

    0.写在前面的话 好久没写博客了,诶,好多时候偷懒直接就抓网上的资料丢笔记里了,也就没有自己提炼,偷懒偷懒.然后最近参加了一个网络课程,要交作业的那种,为了能方便看下其他同学的作业,就写了个爬虫把作业 ...

  2. SpringBoot+SpringSecurity+Thymeleaf认证失败返回错误信息踩坑记录

    Spring boot +Spring Security + Thymeleaf认证失败返回错误信息踩坑记录 步入8102年,现在企业开发追求快速,Springboot以多种优秀特性引领潮流,在众多使 ...

  3. manjaro xfce 18.0 踩坑记录

    manjaro xfce 18.0 踩坑记录 1 简介1.1 Manjaro Linux1.2 开发桌面环境2 自动打开 NumLock3 系统快照3.1 安装timeshift3.2 使用times ...

  4. HDP 3.1.0 集成 Sqoop2 踩坑问题记录

    HDP 3.1.0 集成 Sqoop2 踩坑问题记录 本文原始地址:https://sitoi.cn/posts/65261.html 问题一 $ sqoop:000> start job -n ...

  5. Tars | Win10下Docker部署TarsJava(SpringBoot)全过程及踩坑记录

    @ 目录 前言 1. 相关环境版本: 坑点一:VMware与Win10 Docker冲突 坑点二:20.版本TarsJava(SpringBoot)依赖文件缺失 2. Docker安装: 坑点三:Do ...

  6. XXLJOB2.1.0数据源配置踩坑记录

    最近在看XXLJOB,因为截至到发文时间最新的版本是2.1.0而且需要建立的数据库与Quartz解耦了,所以就用了最新的版本. 首先说一下踩坑过程: 代码开发完成之后,在定时跑的时候第一次跑的多数失败 ...

  7. Springboot+Mybatis+MySQL实例练习时踩坑记录

    最近刚开始学习后端,直接让上手学习Springboot+Mybatis+MySQL对CRUD的实例,虽然实例不难,但是上面的三个知识我都不懂,就有点为难我了 所以经常遇到一个点卡自己很久的情况,这里列 ...

  8. Spring-Boot + MyBatis-Plus 踩坑记录

    这两天在学SpringBoot+MyBatis的开发,配置开发环境和DEMO的过程中踩了很多坑,在这里记录一下. 我的开发环境是idea + JDK 1.8.0.211. 首先展示一下demo的项目整 ...

  9. .NET CORE 2.0 踩坑记录之ConfigurationManager

    在之前.net framework 中使用的ConfigurationManager还是很方便的,不过在.NET CORE 2.0中SDK默认已经不存在ConfigurationManager. 那么 ...

随机推荐

  1. [强网杯2019]upload buuoj

    提示:重点在这,可节省大部分时间 扫描后台 发现www.tar.gz备份文件. 这平台有429[太多请求限制]防护.dirsearch扫描一堆429.于是用了最笨的方法. 文件上传 先注册个账号 注册 ...

  2. .NET如何快速比较两个byte数组是否相等

    目录 前言 评测方案 几种不同的方案 For循环 Memcmp 64字长优化 SIMD Sse Avx2 SequenceCompare 总结 参考文献 前言 之前在群里面有群友问过一个这样的问题,在 ...

  3. 第一阶段:Java基础之OOP

    OOP:面向对象编程 三大特征: 封装 继承 多态

  4. Power App门户

    1.创建门户 在powerapp应用中添加新应用选择:门户. 填写名称和地址,地址写完后会检测可用,创建会等待几分钟. 2.门户组件 节,容器分为1.2.3列 1.文本:可编辑字体 2.图像:可选择连 ...

  5. Oracle数据库包括两个部分数据库和数据库实例

    olsnodes,这个命令用来显示集群点列表(grid即oracle rac的第三个安装包内的软件,可找到) //集群名称[grid@shdb02 ~]$ olsnodes -cshfpdb-clus ...

  6. linux三剑客试题汇总

    1.找出/proc/meminfo文件中以s开头的行,至少用三种方式忽略大小写 [root@localhost ~]# grep -E '^[sS]' /proc/meminfo [root@loca ...

  7. java实现二叉树的Node节点定义手撕8种遍历(一遍过)

    java实现二叉树的Node节点定义手撕8种遍历(一遍过) 用java的思想和程序从最基本的怎么将一个int型的数组变成Node树状结构说起,再到递归前序遍历,递归中序遍历,递归后序遍历,非递归前序遍 ...

  8. NodeJs学习日报day5——导入模块

    const { match } = require("assert") function dateFormat(dataStr) { const dt = new Date(dat ...

  9. SpringMVC踩坑3——前后端传值问题

    在前端页面点击修改,同时把需要修改的ID传到后端,后端根据ID去修改具体数据 这是前端代码 <a href="${pageContext.request.contextPath}/bo ...

  10. Web项目部署指南

    Web项目部署指南 本文记录了部署Vue项目到阿里云服务器上的过程,其中云服务器的操作系统是CentOS 7,Web服务器用的是nginx.因为项目涉及发送异步请求,而由Flask编写的后端应用监听的 ...