整合springboot+redis,一直失败,发现是common-pool2版本问题。

文章描述了一个SpringBoot应用程序在启动时遇到的问题,具体是由于尝试调用不存在的方法导致ApplicationContext无法启动。问题根源在于不同版本的类库冲突,即spring-boot-autoconfigure和commons-pool2之间的不兼容。解决方案是删除common-pool2依赖中的version标签,确保应用使用兼容的类库版本。经过修改后,应用成功启动并能正常访问。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-03-10 08:30:59.330 ERROR 26904 --- [           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:188)

The following method did not exist:

    org.apache.commons.pool2.impl.GenericObjectPoolConfig.setMaxWait(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/Hoga/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/2.6.4/spring-boot-autoconfigure-2.6.4.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/Hoga/.m2/repository/org/apache/commons/commons-pool2/2.6.0/commons-pool2-2.6.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/Hoga/.m2/repository/org/apache/commons/commons-pool2/2.6.0/commons-pool2-2.6.0.jar
    org.apache.commons.pool2.impl.BaseObjectPoolConfig: file:/C:/Users/Hoga/.m2/repository/org/apache/commons/commons-pool2/2.6.0/commons-pool2-2.6.0.jar
    org.apache.commons.pool2.BaseObject: file:/C:/Users/Hoga/.m2/repository/org/apache/commons/commons-pool2/2.6.0/commons-pool2-2.6.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

 

 

解决问题:

引入spring2.X集成redis所需common-pool2依赖中,把version删了。

 

 修改完成重新启动:不报错 

访问成功

 

附上redis所需的依赖


   
  1. <!-- redis -- >
  2. <dependency >
  3. <groupId >org.springframework.boot < /groupId >
  4. <artifactId >spring-boot-starter-data-redis < /artifactId >
  5. < /dependency >
  6. <!-- spring 2.X集成redis所需common-pool 2-- >
  7. <dependency >
  8. <groupId >org.apache.commons < /groupId >
  9. <artifactId >commons-pool 2 < /artifactId >
  10. < /dependency >

Spring Boot 2.0中,默认使用Lettuce客户端来连接Redis服务。默认情况下,不使用连接池,只有在配置`redis.lettuce.pool`属性后才能使用Redis连接池。 使用连接池可以提升性能。例如,在插入1万条数据时,如果配置了连接池,执行速度会比没有配置连接池快很多[2]。 在Spring Boot中,使用Lettuce连接池时,可以配置连接池的大小。比如,如果当前连接池中已经有3个连接,再加上当前查询窗口的连接,一共就是4个socket连接。通过配置连接池大小,可以控制同时处理的连接数,以及减少与Redis服务器的重复建立和断开连接的开销。 综上所述,Spring Boot整合Redis连接池可以通过配置`redis.lettuce.pool`属性来启用,并且可以提升性能和优化连接管理。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [SpringBoot 配置 Redis 连接池](https://blog.youkuaiyun.com/web18334137065/article/details/126114299)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [springboot2整合redis使用lettuce连接池(解决lettuce连接池无效问题)](https://blog.youkuaiyun.com/qq_41921994/article/details/109627736)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值