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

项目环境: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. Jmeter(四十四) - 从入门到精通高级篇 - Jmeter远程启动(本地运行+远程运行)(详解教程)

    1.简介 这篇文章其实很简单,就是为下一篇文章做一个铺垫,所以宏哥给小伙伴或童鞋们提前热身一下. 2.什么是远程运行? 远程执行,就是脚本放在本地,执行却在另一台电脑上执行,当然,可以是远程多台电脑一 ...

  2. ESLint语法报错问题

    编写javaScript过程中ESLint语法报错问题 ESLint语法要求: 双引号""需要替换成单引号'' 分号不允许出现 ()之前需要一个空格比如 login () (VSC ...

  3. LTP--linux稳定性测试 linux性能测试 ltp压力测试 ---IBM 的 linux test project

    LTP--linux稳定性测试 linux性能测试 ltp压力测试 ---IBM 的 linux test project Peter盼 2014-04-23 11:25:49  20302  收藏  ...

  4. Python re 截取文本中IP地址及用户名

    文本示例: ts=2019-07-10T06:43:06523942Z pid=1875 tid=6320 version=e73c536 proto=http id=5a61a613e395f883 ...

  5. Linux_用户和组管理

    一.用户分类 1.管理员和普通用户 1️⃣:管理员   --    用户ID:0 2️⃣:普通用户 --   用户ID:1-65535 2.普通用户又分为系统用户和登陆用户 1️⃣:系统用户 -- 用 ...

  6. linux中级之ansible配置(roles)

    一.roles介绍 什么情况下用到roles? 假如我们现在有3个被管理主机,第一个要配置成httpd,第二个要配置成php服务器,第三个要配置成MySQL服务器.我们如何来定义playbook? 第 ...

  7. 入坑java工程师那些事

    最近在知乎上看到好多关于转行做java的朋友,有的在担心学历,有的在想着如何学习java,有的在纠结如何面试.作为一个工作了近10年的java程序员来聊聊我的一些想法,主要从学历.个人能力.工作环境等 ...

  8. MongoDB(13)- 查询操作返回指定的字段

    插入测试数据 db.inventory.insertMany( [ { item: "journal", status: "A", size: { h: 14, ...

  9. MyBatis-编写自定义分页插件

    一.基础知识 本文测试和源码分析参考版本: Mybatis-version:3.5.5 本文相关测试源代码:https://github.com/wuya11/mybatis_demo 1.1 参考方 ...

  10. GO语言常用标准库01---strings包

    package main import ( "fmt" "strings" ) func main031() { fmt.Printf("字符形式:% ...