springboot解决NoClassDefFoundError: redis/clients/jedis/util/SafeEncoder问题
这个问题纯粹是版本不兼容问题,是因为 spring-data-redis 与 jedis 的版本不兼容造成的,一般使用jedis时会出现类似问题,特别是使用jedis进行多redis数据源自定义配置时容易出现。
解决办法
步骤一
首先查看你所依赖的 spring-data-redis 版本,如果是springboot则依赖spring-boot-starter-data-redis,其内部包含了 spring-data-redis,查看其具体版本。

如图所示:
可以看到我所依赖的 spring-boot-starter-data-redis 版本是 2.0.9.RELEASE,而其内部依赖的 spring-data-redis 版本是 2.5.1
步骤二
根据查处的 spring-data-redis 版本,去maven中心仓库查看其对应的jedis版本。

在此页面中总全局搜索jedis即可

可以看到对应的jedis版本应该为3.6.0,接下来修改pom文件中的jedis版本为对应版本即可,别忘了清下maven缓存再重启springboot。
最后贴上我自己的pom配置
<!-- redis 缓存操作 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.0.9.RELEASE</version>
<exclusions>
<!-- 不依赖Redis的异步客户端lettuce -->
<exclusion>
<groupId>io.lettuce</groupId>
<artifactId>lettuce-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Redis的异步客户端jedis -->
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>3.6.0</version>
</dependency>总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
相关文章
spring-boot通过@Scheduled配置定时任务及定时任务@Scheduled注解的方法
这篇文章主要介绍了spring-boot通过@Scheduled配置定时任务,文中还给大家介绍了springboot 定时任务@Scheduled注解的方法,需要的朋友可以参考下2017-11-11


最新评论