gpt4 book ai didi

java - Spring Boot 健康检查总是宕机

转载 作者:行者123 更新时间:2023-11-30 06:56:52 24 4
gpt4 key购买 nike

我正在使用 spring boot health。我只想每次都弥补。所以我在下面添加,

@Component
public class AggregationHealth implements HealthIndicator {
@Override
public Health health() {
Health health = Health.up().build();
logger.info("----------------------------Health status : " + health.getStatus() + "----------------------------");
return health;
}
}

日志显示状态为 Up 但当我使用以下 url 访问我的应用程序时,它显示为 Down。

http://localhost:8085/health

我还在我的 pom.xml 中添加了以下内容,

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

编辑:

一旦我添加 "endpoints.health.sensitive=false" 它会给我下面的描述性错误,

{
"status": "DOWN",
"aggregationHealth": {
"status": "UP"
},
"diskSpace": {
"status": "UP",
"free": 371498577920,
"threshold": 10485760
},
"mongo": {
"status": "DOWN",
"error": "org.springframework.dao.DataAccessResourceFailureException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=localhost:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.ConnectException: Connection refused: connect}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=localhost:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.ConnectException: Connection refused: connect}}]"
}
}

因此,由于 mongo 已关闭,我在我的 application.properties 文件中添加了 mongo 数据库详细信息。但我的问题是,我的服务不需要 mongodb。我什至还添加了 spring.data.mongodb.repositories.enabled=false。在那种情况下,我如何在不指定 mongo 详细信息的情况下进行健康检查?

最佳答案

您可以删除对 Mongo 的依赖,或者如果您只想禁用 MongoDB 的健康指示器,请添加以下属性:

management.health.mongo.enabled=false

关于java - Spring Boot 健康检查总是宕机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34000774/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com