一 前言
springboot 额外的特色是提供了后台应用监控,可以通过 HTTP 或者 JMX的方式管理监控应用,本文主讲HTTP方式;其主要的功能是监控应用的健康状态,查看环境变量等;
二 pom.xml
springboot 2.1.1,主要引入 actuator 依赖,web依赖用于测试;
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
三 默认开启端点
3.1 默认端点 health
直接编写主程序入口,启动;浏览器输入 http://localhost:8080/actuator/health;结果如下,状态是UP;

翻翻源码heath状态码如下
public OrderedHealthAggregator() {
this.setStatusOrder(Status.DOWN, Status.OUT_OF_SERVICE, Status.UP, Status.UNKNOWN);
}
- DOWN 服务无法获得,状态码503;
- .OUT_OF_SERVICE 服务无法获得,状态码503;
- UP 获得服务,状态码200;
- UNKNOWN 获得未知服务,状态码200;
在 application.yml 中配置 healthy 信息 示例如下:
management: endpoint: health: show-details: always
打印详细信息:

基本配置如下:
never :默认,表示不显示详细信息;when-authorized:详细信息显示给 认证过的用户;使用
management.endpoint.health.roles 配置always: 显示详细信息给所有用户3.2 默认端点 info
浏览器输入 http://localhost:8080/actuator/info; 展示空信息如下图:

在application.yml 中 配置工程 info 信息 示例如下;
#配置信息info: actuator: name: springboot-actutor version: 1.0.0 author: zszxz
展示结果如下:

四 HTTP端点说明
|