广告位联系
返回顶部
分享到

升级springboot3.x踩坑记录

java 来源:互联网 作者:佚名 发布时间:2024-05-09 22:06:42 人浏览
摘要

0x01 redis连接异常 先贴一张项目启动的堆栈信息 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 2023-02-06 11:20:14:162 WARN

0x01 redis连接异常

先贴一张项目启动的堆栈信息

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

2023-02-06 11:20:14:162 WARN   [boundedElastic-1] o.s.b.a.d.r.RedisReactiveHealthIndicator -Redis health check failed

org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis

    at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.translateException(LettuceConnectionFactory.java:1602)

    at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1533)

    at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getNativeConnection(LettuceConnectionFactory.java:1358)

    at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$SharedConnection.getConnection(LettuceConnectionFactory.java:1341)

    at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getSharedReactiveConnection(LettuceConnectionFactory.java:1083)

    at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getReactiveConnection(LettuceConnectionFactory.java:479)

    at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getReactiveConnection(LettuceConnectionFactory.java:105)

    at reactor.core.publisher.MonoSupplier.call(MonoSupplier.java:67)

    at reactor.core.publisher.FluxSubscribeOnCallable$CallableSubscribeOnSubscription.run(FluxSubscribeOnCallable.java:227)

    at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:68)

    at reactor.core.scheduler.SchedulerTask.call(SchedulerTask.java:28)

    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)

    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)

    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)

    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)

    at java.base/java.lang.Thread.run(Thread.java:833)

Caused by: org.springframework.data.redis.connection.PoolException: Could not get a resource from the pool

    at org.springframework.data.redis.connection.lettuce.LettucePoolingConnectionProvider.getConnection(LettucePoolingConnectionProvider.java:105)

    at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1531)

    ... 14 common frames omitted

Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to localhost/<unresolved>:6379

    at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78)

    at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:56)

    at io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:350)

    at io.lettuce.core.RedisClient.connect(RedisClient.java:216)

    at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.lambda$getConnection$1(StandaloneConnectionProvider.java:111)

    at java.base/java.util.Optional.orElseGet(Optional.java:364)

    at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.getConnection(StandaloneConnectionProvider.java:111)

    at org.springframework.data.redis.connection.lettuce.LettucePoolingConnectionProvider.lambda$getConnection$0(LettucePoolingConnectionProvider.java:93)

    at io.lettuce.core.support.ConnectionPoolSupport$RedisPooledObjectFactory.create(ConnectionPoolSupport.java:211)

    at io.lettuce.core.support.ConnectionPoolSupport$RedisPooledObjectFactory.create(ConnectionPoolSupport.java:201)

    at org.apache.commons.pool2.BasePooledObjectFactory.makeObject(BasePooledObjectFactory.java:70)

    at org.apache.commons.pool2.impl.GenericObjectPool.create(GenericObjectPool.java:571)

    at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:298)

    at org.apache.commons.pool2.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:223)

    at io.lettuce.core.support.ConnectionPoolSupport$1.borrowObject(ConnectionPoolSupport.java:122)

    at io.lettuce.core.support.ConnectionPoolSupport$1.borrowObject(ConnectionPoolSupport.java:117)

    at org.springframework.data.redis.connection.lettuce.LettucePoolingConnectionProvider.getConnection(LettucePoolingConnectionProvider.java:99)

    ... 15 common frames omitted

Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information: localhost/127.0.0.1:6379

Caused by: java.net.ConnectException: Connection refused: no further information

    at java.base/sun.nio.ch.Net.pollConnect(Native Method)

    at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)

    at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:946)

    at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:337)

    at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334)

    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:776)

    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)

    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)

    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)

    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)

    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)

    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)

    at java.base/java.lang.Thread.run(Thread.java:833)

在升级springboot3.x后启动项目发现redis连接报错了,根据堆栈异常信息发现redis竟然去链接了本地服务,该项目使用了Nacos配置也都在上,突然的异常感觉挺奇怪的,本来以为是升级后无法拉取到Nacos的配置信息了后经验证使用@Value注解或者其他配置类均未发生该问题,那就只能怀疑是spring对redis的配置支持改变了,所以直接点就去找了redis的自动配置类发现确实改变了配置前缀为spring.data.redis(原该项目springboot版本为2.7.4时redis配置前缀为spring.redis)贴一下版本属性内容对比图

3.x版本时:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

@ConfigurationProperties(prefix = "spring.data.redis")

public class RedisProperties {

 

    /**

     * Database index used by the connection factory.

     */

    private int database = 0;

 

    /**

     * Connection URL. Overrides host, port, and password. User is ignored. Example:

     * redis://user:password@example.com:6379

     */

    private String url;

 

    /**

     * Redis server host.

     */

    private String host = "localhost";

 

    /**

     * Login username of the redis server.

     */

    private String username;

 

    /**

     * Login password of the redis server.

     */

    private String password;

 

    /**

     * Redis server port.

     */

    private int port = 6379;

 

    /**

     * Whether to enable SSL support.

     */

    private boolean ssl;

 

    /**

     * Read timeout.

     */

    private Duration timeout;

 

    /**

     * Connection timeout.

     */

    private Duration connectTimeout;

 

    /**

     * Client name to be set on connections with CLIENT SETNAME.

     */

    private String clientName;

 

    /**

     * Type of client to use. By default, auto-detected according to the classpath.

     */

    private ClientType clientType;

 

    private Sentinel sentinel;

 

    private Cluster cluster;

 

    private final Jedis jedis = new Jedis();

 

    private final Lettuce lettuce = new Lettuce();

 

}

2.7.4版本时:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

@ConfigurationProperties(prefix = "spring.redis")

public class RedisProperties {

 

    /**

     * Database index used by the connection factory.

     */

    private int database = 0;

 

    /**

     * Connection URL. Overrides host, port, and password. User is ignored. Example:

     * redis://user:password@example.com:6379

     */

    private String url;

 

    /**

     * Redis server host.

     */

    private String host = "localhost";

 

    /**

     * Login username of the redis server.

     */

    private String username;

 

    /**

     * Login password of the redis server.

     */

    private String password;

 

    /**

     * Redis server port.

     */

    private int port = 6379;

 

    /**

     * Whether to enable SSL support.

     */

    private boolean ssl;

 

    /**

     * Read timeout.

     */

    private Duration timeout;

 

    /**

     * Connection timeout.

     */

    private Duration connectTimeout;

 

    /**

     * Client name to be set on connections with CLIENT SETNAME.

     */

    private String clientName;

 

    /**

     * Type of client to use. By default, auto-detected according to the classpath.

     */

    private ClientType clientType;

 

    private Sentinel sentinel;

 

    private Cluster cluster;

 

    private final Jedis jedis = new Jedis();

 

    private final Lettuce lettuce = new Lettuce();

 

}

至此问题解决。


版权声明 : 本文内容来源于互联网或用户自行发布贡献,该文观点仅代表原作者本人。本站仅提供信息存储空间服务和不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权, 违法违规的内容, 请发送邮件至2530232025#qq.cn(#换@)举报,一经查实,本站将立刻删除。

您可能感兴趣的文章 :

原文链接 :
    Tag :
相关文章
  • Springboot限制IP访问指定的网址实现

    Springboot限制IP访问指定的网址实现
    IP黑白名单是网络安全管理中常见的策略工具,用于控制网络访问权限,根据业务场景的不同,其应用范围广泛 方式一: 添加一个简单的白
  • MybatisPlus多条件or()的使用问题小结

    MybatisPlus多条件or()的使用问题小结
    搞混了一次,特此笔记 1、bitCode or iotStr 跟其他ID一个都不能有重复 1 2 queryWrapper.ne(LineProductionPlan::getId,bean.getId()); queryWrapper.and(i - i.eq(LineP
  • 升级springboot3.x踩坑记录
    0x01 redis连接异常 先贴一张项目启动的堆栈信息 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 4
  • springBoot连接远程Redis连接失败的问题解决
    问题: 首先,我是先用jedis进行的redis连接,成功连接,没有任何问题,说明redis配置,以及访问地址、端口、密码都是正确的。 我的yml文件
  • Java Stream API详解与使用介绍

    Java Stream API详解与使用介绍
    本文全面介绍了 Java Stream API 的概念、功能以及如何在 Java 中有效地使用它进行集合和数据流的处理。通过详细解释和示例,文章展示了 J
  • Springboot如何使用外部yml启动

    Springboot如何使用外部yml启动
    Springboot使用外部yml启动 有时候我们想更灵活的使用配置文件,例如同一套代码去部署多个客户,此时差异大的地方其实只是配置文件,这是
  • java如何获取视频文件的编解码器代码
    引入jar包: 1 2 3 4 5 dependency groupIdorg.bytedeco/groupId artifactIdjavacv-platform/artifactId version1.5.9/version /dependency 测试类 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  • Java服务cpu100%的解决过程分享

    Java服务cpu100%的解决过程分享
    背景 最近一个任务是优化一个导出的功能,但是点击功能时发现,程序长时间无反应,过一段时间又有反应,通过查看服务的监控发现,服
  • Spring中实现策略模式的几种方式小结
    一.背景 在写业务代码的时候,难免会遇到很多if-else,这个时候如果if-else不是很多可以用if-else。如果此时场景过多,太多的if-else会导致代
  • mybatis解决<foreach>标签不能超过1000的问题
    错误写法: 1 2 3 4 5 6 7 8 select id=getProductInfoList resultType=vo select a.name from A a where a.idin foreach collection=ids item=item index=index open=( close=) separator=
  • 本站所有内容来源于互联网或用户自行发布,本站仅提供信息存储空间服务,不拥有版权,不承担法律责任。如有侵犯您的权益,请您联系站长处理!
  • Copyright © 2017-2022 F11.CN All Rights Reserved. F11站长开发者网 版权所有 | 苏ICP备2022031554号-1 | 51LA统计