Zipkin start和redis start兼容性问题

  • Spring boot 版本: 2.2.1.RELEASE
  • Spring cloud 版本 : Hoxton.RC1

项目中同时使用了

  • spring-cloud-starter-zipkin
  • spring-boot-starter-data-redis
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

在编码中有多个Service同时注入了RedisTemplate<String, String> redisTemplate导致在Tomcat启动时报错,导致无法运行。

错误如下

[ main] o.a.c.loader.WebappClassLoaderBase : The web application
[ROOT] appears to have started a thread named [lettuce-eventExecutorLoop-1-1] but has failed to stop it. This is very likely to create a memory leak.
Stack trace of thread:
sun.misc.Unsafe.park(Native Method)`

Caused by: org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisException: Cannot retrieve initial cluster partitions from initial URIs [RedisURI [host=‘172.31.214.234’, port=6380], RedisURI [host=‘172.31.214.234’, port=6381], RedisURI [host=‘172.31.214.235’, port=6380], RedisURI [host=‘172.31.214.235’, port=6381], RedisURI [host=‘172.31.214.236’, port=6380], RedisURI [host=‘172.31.214.236’, port=6381]

最终原因是Redis 客户端lettuce无法连接上Redis导致该报错。

解决

移除spring-boot-starter-data-redis中对lettuce的引用,加入jedis的依赖。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
    <exclusions>
        <exclusion>
            <groupId>io.lettuce</groupId>
            <artifactId>lettuce-core</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>redis.clients</groupId>
    <artifactId>jedis</artifactId>
</dependency>

当我移除spring-cloud-starter-zipkin 之后再次启动项目发现启动成功,spring-boot-starter-data-redis默认使用lettuce作为Redis的客户端,因此推断为spring-cloud-starter-zipkin 可能和lettuce有兼容性问题。

因此尝试把lettuce换为jedis,问题解决。

参考

[1]. 简书 . heichong . Spring boot - data-redis与jedis关系. https://www.jianshu.com/p/c7b4cd47ad65

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值