health检查一般用于spring cloud注册中心的存活检查,比如spring cloud consul配置

spring:
  cloud:
    consul:
      discovery:
        register: true
        instance-id: ${spring.application.name}:${server.port}
        service-name: ${spring.application.name}
        port: ${server.port}
        healthCheckPath: /actuator/health
        healthCheckInterval: 15s
      config:
        discovery:
          enabled: true
          service-id: ${spring.application.name}:${server.port}
        fail-fast: true

实现方式

pom引入

<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-starter-actuator</artifactId>

</dependency>

检查页面

/actuator/health

返回

{"status":"UP"}

如果返回为down,监听

org.springframework.boot.actuate.health.HealthEndpoint

中的health()方法,找到down的连接。