(1)首先我们引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
(2)在主配置文件application.properties中添加配置信息
management.endpoints.web.exposure.include=*
management.endpoint.health.enabled=true
(3) 实现HealthIndicator 此接口并实现检测方法,例如
package com.ccbobe.websocket.health;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.stereotype.Component;
@Component
public class CheckHealth implements HealthIndicator {
@Override
public Health health() {
return Health.up().withDetail("正常",true).build();
}
}
(4)在开发工具中即可看到
如果使用 spring admin 则可以显示先监控页面中。