redis 报错 NoSuchFieldError: DEFAULT
具体报错如下:
Exception in thread "main" java.lang.NoSuchFieldError: DEFAULT
at io.lettuce.core.AbstractRedisClient.connectionBuilder(AbstractRedisClient.java:222)
at io.lettuce.core.RedisClient.connectStatefulAsync(RedisClient.java:313)
at io.lettuce.core.RedisClient.connectStandaloneAsync(RedisClient.java:278)
at io.lettuce.core.RedisClient.connect(RedisClient.java:211)
at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.lambda$getConnection$1(StandaloneConnectionProvider.java:115)
at java.util.Optional.orElseGet(Optional.java:267)
at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.getConnection(StandaloneConnectionProvider.java:115)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1459)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:1247)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getConnection(LettuceConnectionFactory.java:1230)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getSharedConnection(LettuceConnectionFactory.java:979)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getConnection(LettuceConnectionFactory.java:359)
at org.springframework.data.redis.core.RedisConnectionUtils.fetchConnection(RedisConnectionUtils.java:193)
at org.springframework.data.redis.core.RedisConnectionUtils.doGetConnection(RedisConnectionUtils.java:144)
at org.springframework.data.redis.core.RedisConnectionUtils.getConnection(RedisConnectionUtils.java:105)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:209)
at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:189)
at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:96)
at org.springframework.data.redis.core.DefaultValueOperations.get(DefaultValueOperations.java:53)
at com.dingxuan.sky.dxp.udp.client.SkyDxpUdpClientApplication.main(SkyDxpUdpClientApplication.java:21)
依赖版本
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>2.4.5</version>
</dependency>
<!--redis 里面依赖了 lettuce的版本 ,如下图-->
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>5.0.0.Alpha1</version>
</dependency>
redis里面依赖了lettuce的版本,lettuce本身集成了netty 4.1 的版本,与项目本身集成的5.0 版本冲突。
解决办法:
-
将本身集成的netty的版本与lettuce的版本改成一致的。
-
去掉lettuce 改集成 jedis
依赖jedis版本需要查看 spring-boot-starter-data-redis 对应的jedis版本,2.4.5 默认对应 jedis 的 3.3.0版本