SpringBoot访问Redis报错java.lang.NoSuchMethodError: redis.clients.jedis.JedisPoolConfig.setMinEvictableIdleTime

完整报错信息:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed;
nested exception is java.lang.NoSuchMethodError: redis.clients.jedis.JedisPoolConfig.setMinEvictableIdleTime(Ljava/time/Duration;)V] with root cause

java.lang.NoSuchMethodError: redis.clients.jedis.JedisPoolConfig.setMinEvictableIdleTime(Ljava/time/Duration;)V

 

原因1:

Maven中有其它组件依赖了旧版的jedis,需要排除

 

原因1的解决方法:

在使用了旧版jedis的组件的<dependency></dependency>中加入排除旧版jedis的依赖

<exclusions>
    <exclusion>
        <groupId>redis.clients</groupId>
        <artifactId>jedis</artifactId>
    </exclusion>
</exclusions>

重新加载Maven的依赖组件,重新运行即可。

 

原因2:

JedisPoolConfig和JedisSentinelPool使用了apache.commons的commons-pool2包

虽然编译代码时不会报错,但运行时会提示找不到包。(怀疑是用反射使用的原因)

 

原因2的解决方法:

在pom.xml的<dependencies></dependencies>中加入以下配置:

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

重新加载Maven的依赖组件,重新运行即可。

 

posted @ 2022-01-12 01:16  Clotho_Lee  阅读(3217)  评论(0编辑  收藏  举报