最近是重新开发整个项目,在上线测试的时候发现这个问题。

项目环境:SpringBoot2.x+Consul+Redission+Maven

报错的信息如下:

o.s.b.a.redis.RedisHealthIndicator - Redis health check failed
org.springframework.data.redis.RedisConnectionFailureException: Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool

项目中引用了健康检查

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

通过spring-boot-actuator-autoconfigure:2.1.13.RELEASE的jar包找到了源码

源代码如下:

@Configuration
@ConditionalOnClass(RedisConnectionFactory.class)
@ConditionalOnBean(RedisConnectionFactory.class)
@ConditionalOnEnabledHealthIndicator("redis")
@AutoConfigureBefore(HealthIndicatorAutoConfiguration.class)
@AutoConfigureAfter({ RedisAutoConfiguration.class, RedisReactiveHealthIndicatorAutoConfiguration.class })
public class RedisHealthIndicatorAutoConfiguration
extends CompositeHealthIndicatorConfiguration<RedisHealthIndicator, RedisConnectionFactory> { private final Map<String, RedisConnectionFactory> redisConnectionFactories; public RedisHealthIndicatorAutoConfiguration(Map<String, RedisConnectionFactory> redisConnectionFactories) {
this.redisConnectionFactories = redisConnectionFactories;
} @Bean
@ConditionalOnMissingBean(name = "redisHealthIndicator")
public HealthIndicator redisHealthIndicator() {
return createHealthIndicator(this.redisConnectionFactories);
} }

解决方法1:

通过@ConditionalOnEnabledHealthIndicator可以知道解决办法,在配置文件中禁用redis检查

management:
health:
redis: ---禁用redis检查
# defaults: ---也可以禁用,不推荐
enabled: false

解决方法2:

查看源码发现RedisHealthIndicator继承AbstractHealthIndicator,AbstractHealthIndicator实现了HealthIndicator接口。我们可以通过自定义配置来解决。

@Configuration
public class RedisHealthIndicator implements HealthIndicator{ @Override
public Health health() {
return Health.up().build();
}
}

注意:我们必须要将原有的RedisHealthIndicator类覆盖,所以class名为RedisHealthIndicator。如果类想另起名则需指定bean名为redisHealthIndicator,否则还是会出现错误信息。

最后说下自己遇到的原因吧!属实有点尴尬。

自己项目上线遇到的问题则是怪自己粗心。只在redisson的配置文件中配置了redis连接,忘记在application.yml配置redis的连接信息。

项目启动报错:Redis health check failed的更多相关文章

  1. springboot项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedde

    springboot项目启动报错Failed to configure a DataSource: 'url' attribute is not specified and no embedde 创建 ...

  2. SSM项目启动报错:Failed to read candidate component class

    SSM项目启动报错:Failed to read candidate component class 换成3.1又没有问题,换成3.2又不行,查看编译环境用的是1.8,将1.8降为1.7,问题解决,服 ...

  3. Linux下Tomcat项目启动报错

    Linux下Tomcat项目启动报错 org.springframework.beans.factory.CannotLoadBeanClassException: Error loading cla ...

  4. Eureka Server项目启动报错处理

    Eureka Server项目启动报错处理 Eureka是一个服务发现组件,提供服务注册.发现等注册中心功能,使用spring boot启动eureka应用时出现报错: 20:36:17.646 [r ...

  5. (转)Eclipse4.2 Tomcat启动报错 A child container failed during start

     Eclipse4.2 Tomcat启动报错 A child container failed during start 2013-5-21 15:02:24 org.apache.catalina. ...

  6. vue项目启动报错 spawn cmd ENOENT errno: -4058

    vue项目启动报错 spawn cmd ENOENT errno: -4058 运行vue项目(npm run dev)报错 提示 'npm' 不是内部或外部命令 cmd输入node -v 有版本号 ...

  7. eclipse 中导入 maven项目 启动报错

    导入Maven项目到Eclipse中时,出现问题如下: java.lang.ClassNotFoundException: org.springframework.web.context.Contex ...

  8. AndroidStudio导入开源项目提示报错:Gradle sync failed: SSL peer shut down incorrectly

    问题描述: AndroidStudio导入开源项目提示报错:Gradle sync failed: SSL peer shut down incorrectly (1 m 12 s 92 ms) 解决 ...

  9. 创建spring boot项目启动报错遇到的问题

    1.Spring boot,Mybatis 启动报错 Failed to auto-configure a DataSource *************************** APPLICA ...

随机推荐

  1. 用fread和fwrite实现文件复制操作

    #include <stdio.h> #include <stdlib.h> #include <string.h> int main(int argc,char ...

  2. Uva 642 - Word Amalgamation sort qsort

     Word Amalgamation  In millions of newspapers across the United States there is a word game called J ...

  3. [刷题] 235 Lowest Common Ancestor of a Binary Search Tree

    要求 给定一棵二分搜索树和两个节点,寻找这两个节点的最近公共祖先 示例 2和8的最近公共祖先是6 2和4的最近公共祖先是2 思路 p q<node node<p q p<=node& ...

  4. VBA绘制Excel图表

    VBA调试运行进入: 几个例子: 删除工作表内所有图表 录制一个宏 简化宏再使用 大量图表可采用for循环 CSDN上用积分下载的一个例子 VBA数组 VBA调试运行进入: 右键Excel的Sheet ...

  5. BUUCTF(九) [ACTF2020 新生赛]Exec 1

    baidu.com & ls .. baidu.com & ls ../.. baidu.com & ls ../../.. 发现flag 查看 baidu.com & ...

  6. Linux中级之netfilter/iptables应用及补充

    一.iptables介绍 Netfilter/Iptables(以下简称Iptables)是unix/linux自带的一款优秀且开放源代码的完全自由的基于包过滤的防火墙工具,它的功能十分强大,使用非常 ...

  7. haproxy env 安装与基础配置

    1. 安装 Use docker.package or source installations to install 第三方仓库 https://pkgs.org/download/haproxy ...

  8. MYSQL导入/迁移后事件不执行

    mysql迁移后事件不执行 查看数据库是否开启事件支持 mysql> show variables like 'event_scheduler'; +-----------------+---- ...

  9. GO学习-(32) Go实现日志收集系统1

    Go实现日志收集系统1 项目背景 每个系统都有日志,当系统出现问题时,需要通过日志解决问题 当系统机器比较少时,登陆到服务器上查看即可满足 当系统机器规模巨大,登陆到机器上查看几乎不现实 当然即使是机 ...

  10. maxscrip_import_csv_构建对象

    3DMAX通过脚本文件批量操作相当有效率,国内关于maxscript的资料比较少,知识点比较零散,逐步进行补充. 导入文件: filepath = "... Data\\01_us.csv& ...