关闭springboot健康检查 org.springframework.boot.actuate.health.AbstractHealthIndicator 89 health - Elastic

本文介绍了一种常见的SpringBoot应用中Elasticsearch健康检查失败的问题及两种解决方法。一种是通过注释掉安全检查依赖来关闭检查,另一种是在配置文件中设置Elasticsearch健康检查为禁用状态。

错误日志:org.springframework.boot.actuate.health.AbstractHealthIndicator 89 health - Elasticsearch health check failed java.net.ConnectException: Connection refused: no further information

出现这个错误是spring对Elasticsearch监测失败,解决方法有两种,第一种是去掉安全检查依赖,第二种是直接关闭安全检查。

方法一:

注释该依赖,关闭检查

 

方法二:

在配置文件加入以下代码

management:
      health:
        elasticsearch:
          enabled: false

 

 

Error creating bean with name 'documentationPluginsBootstrapper' defined in URL [jar:file:/C:/Users/28122/.m2/repository/io/springfox/springfox-spring-web/3.0.0/springfox-spring-web-3.0.0.jar!/springfox/documentation/spring/web/plugins/DocumentationPluginsBootstrapper.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webMvcRequestHandlerProvider' defined in URL [jar:file:/C:/Users/28122/.m2/repository/io/springfox/springfox-spring-webmvc/3.0.0/springfox-spring-webmvc-3.0.0.jar!/springfox/documentation/spring/web/plugins/WebMvcRequestHandlerProvider.class]: Unsatisfied dependency expressed through constructor parameter 2; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthEndpointWebMvcHandlerMapping' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointWebExtensionConfiguration$MvcAdditionalHealthEndpointPathsConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.servlet.AdditionalHealthEndpointPathsWebMvcHandlerMapping]: Factory method 'healthEndpointWebMvcHandlerMapping' threw exception; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthEndpoint' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'healthContributorRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Unsatisfied dependency expressed through method 'healthContributorRegistry' parameter 2; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticsearchHealthContributor' defined in class path resource [org/springframework/boot/actuate/autoconfigure/elasticsearch/ElasticSearchRestHealthContributorAutoConfiguration.class]: Unsatisfied dependency expressed through method 'elasticsearchHealthContributor' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'elasticsearchRestClient' defined in class path resource [org/springframework/boot/autoconfigure/elasticsearch/ElasticsearchRestClientConfigurations$RestClientFromRestHighLevelClientConfiguration.class]: Unsatisfied dependency expressed through method 'elasticsearchRestClient' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'restHighLevelClient' defined in class path resource [com/picc/xzpt/piccmp/config/ElasticsearchConfig.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.elasticsearch.client.RestHighLevelClient]: Factory method 'restHighLevelClient' threw exception; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.elasticsearch.client.RestHighLevelClient 启动报异常
最新发布
11-22
`org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator` 是 Spring Boot Actuator 提供的一个健康指示器,用于检查数据源(`DataSource`)的健康状态。在 Spring Boot 应用中,数据库连接的稳定性至关重要,该健康指示器通过执行一个简单的 SQL 查询(通常是 `SELECT 1`)来验证数据源是否能够正常连接到数据库。 ### 功能 - **健康检查**:通过执行一个简单的 SQL 查询来验证数据源是否能够正常连接到数据库。如果查询成功执行,则认为数据源健康;否则,认为数据源不健康。 - **自动配置**:在 Spring Boot 应用中,如果引入了 Actuator 依赖,并且配置了数据源(`DataSource`),则 `DataSourceHealthIndicator` 会自动配置并注册到 Spring Boot健康检查端点中。 - **自定义查询**:可以通过配置 `spring.datasource.health-indicator.query` 属性来指定用于健康检查的 SQL 查询语句。 ### 依赖 要使用 `DataSourceHealthIndicator`,需要在项目中引入 Spring Boot Actuator 依赖。以 Maven 为例,可以在 `pom.xml` 中添加以下依赖: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> ``` ### 配置 默认情况下,`DataSourceHealthIndicator` 会执行 `SELECT 1` 查询来检查数据源的健康状态。如果需要自定义查询语句,可以在 `application.properties` 或 `application.yml` 中进行配置: ```properties spring.datasource.health-indicator.query=SELECT 1 FROM DUAL ``` ```yaml spring: datasource: health-indicator: query: SELECT 1 FROM DUAL ``` ### 查看健康状态 在应用启动后,可以通过访问 `/actuator/health` 端点来查看数据源的健康状态。返回结果中会包含 `db` 部分,显示数据源的健康信息: ```json { "status": "UP", "components": { "db": { "status": "UP", "details": { "database": "MySQL", "hello": 1 } } } } ``` ### 总结 `DataSourceHealthIndicator` 是一个非常实用的工具,它可以帮助开发者实时监控数据源的健康状态,及时发现并解决数据库连接问题。通过简单的配置,就可以将其集成到 Spring Boot 应用中,为应用的稳定性提供保障。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值