【BUG】测试线 redisTemplate失效

项目场景:

需要在测试线请求其他部门的API,以验证量化指标是否能取到数据,由于该测试线机器没有做办公网映射,所以在代码中是用了@PostConstruct 注解,在jar包启动时就会自动执行跑批验证的方法。


问题描述

在验证方法中,有一个步骤需要用redisTemplate查询redis,奇怪的是,在本地能用redisTemplate查询到数据,而在测试线却查不到数据。
到测试线拉日志,看到如下报错:

2023-11-28 14:59:20,520 [pool-3-thread-5] [uid-] ERROR com.eastmoney.approboadvisor.api.cache.BkRelationCacheLoader : BkRelationCacheLoader
java.lang.IllegalStateException: LettuceConnectionFactory was destroyed and cannot be used anymore
at org.springframework.util.Assert.state(Assert.java:76)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.assertInitialized(LettuceConnectionFactory.java:1263)
at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory.getConnection(LettuceConnectionFactory.java:414)
at org.springframework.data.redis.core.RedisConnectionUtils.fetchConnection(RedisConnectionUtils.java:193)

原因分析:

提示:这里填写问题的分析:

看起来是redis连接池断开了连接,所以为啥会断开连接捏,继续查日志:

2023-11-28 15:33:14,781 [main] [uid-] WARN  o.s.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.context.ApplicationContextException: Failed to start bean 'webServerStartStop'; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat server
2023-11-28 15:33:14,782 [main] [uid-] DEBUG org.springframework.data.redis.listener.RedisMessageListenerContainer : Stopped RedisMessageListenerContainer.

可以看到在RedisMessageListenerContainer 停止前,是Tomcat启动失败了,猜测是Tomcat启动失败后使得redis连接监听器关闭,从而使得redisTemplate不可用
那么Tomcat为什么会启动失败捏,继续看日志:

2023-11-28 15:33:14,763 [main] [uid-] INFO  org.apache.coyote.http11.Http11NioProtocol : Starting ProtocolHandler ["http-nio-10.195.xxx.xxx:xxxx"]

···

2023-11-28 15:33:14,764 [main] [uid-] DEBUG org.apache.tomcat.util.net.NioEndpoint : Destroy initiated for /10.195.xxx.xxx:xxxx

所以看来是ip没对,导致Tomcat启动失败,看了下配置,确实没配对···[尴尬]

重新将
LOCAL_IP改为本机地址

重启后就可以顺利跑批了


这里有两点:

1、@PostConstruct 注解的代码与Tomcat在同一时间启动,所以如果不是在@PostConstruct 中写逻辑,其实这个jar包根本不会起得来

2、Tomcat启动失败后会导致springboot启动失败,bean逐个销毁

  • 7
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值