springboot 健康检查总是down

Har*_*ana 2 java spring spring-boot

我正在使用弹簧靴健康。我只是想每次都弥补。所以我在下面补充,

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

日志显示状态为向上,但是当我使用下面的 url 访问我的应用程序时,它显示为向下。

http://localhost:8085/health
Run Code Online (Sandbox Code Playgroud)

我还在我的 pom.xml 下面添加了,

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

编辑:

一旦我添加"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}}]"
  }
}
Run Code Online (Sandbox Code Playgroud)

因此,由于 mongo 已关闭,我在 application.properties 文件中添加了 mongo db 详细信息。但我的问题是,我的服务不需要 mongodb。我什至补充spring.data.mongodb.repositories.enabled=false。在这种情况下,如何在不指定 mongo 详细信息的情况下使健康状况良好?

dun*_*nni 5

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

management.health.mongo.enabled=false
Run Code Online (Sandbox Code Playgroud)