SpringBoot项目监控开发小用例(实例分析)

(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)在开发工具中即可看到

D71EBD89-687C-6323-BBE1-1DD5913EA5BD.png

如果使用 spring admin 则可以显示先监控页面中。

收藏 (0)
评论列表
正在载入评论列表...
我是有底线的