三合一网站有必要吗,花园之家wordpress,有了主机和域名后如何做网站,网站速成说明#xff1a;本文介绍Spring Boot Actuator的使用#xff0c;关于Spring Boot Actuator介绍#xff0c;下面这篇博客写得很好#xff0c;珠玉在前#xff0c;我就不多介绍了。
Spring Boot Actuator
简单使用
项目里引入下面这个依赖
!--Spring Boot Actuator依…说明本文介绍Spring Boot Actuator的使用关于Spring Boot Actuator介绍下面这篇博客写得很好珠玉在前我就不多介绍了。
Spring Boot Actuator
简单使用
项目里引入下面这个依赖
!--Spring Boot Actuator依赖--
dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-actuator/artifactId
/dependency增加以下配置开放所有默认接口
management:endpoints:web:exposure:include: *启动项目浏览器输入http://127.0.0.1:8081/actuator可见以下接口信息 输入某个详细的接口名称如http://127.0.0.1:8081/actuator/health查询详细的内容如下 配置文件中添加配置查看更详细的内容
management:# 开放所有接口endpoints:web:exposure:include: *# 单个接口设置endpoint:health:show-details: ALWAYS如下 手动自定义一个接口如下
import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.stereotype.Component;Component
Endpoint(id my-actuator)
public class MyActuator {ReadOperationpublic String hello() {return Good Luck;}
}其中Endpoint(id my-actuator)可以等同于RequestMapping(/my-actuator)浏览器敲http://127.0.0.1:8081/actuator/可见自定义的接口如下 浏览器输http://127.0.0.1:8081/actuator/my-actuator可见接口返回 使用场景
通过上面的简单使用可以看到 Spring Boot Actuator与我们常写的接口是分别开的有点像swagger。他可以有以下的使用场景 健康检查默认的health就是用来扩展健康检查的我们可以在代码里去扩展这个接口来实现自己的健康检查操作 监控可以写一些接口接口内返回运行时系统内的一些指标收集起来观测运行时的情况 统计如上有些数据是“活”的不存数据库或者日志里服务停止数据就消失了这些数据就可以在接口里返回用于统计 排查问题有些数据可能是存在本地缓存如某个Map中的就可以写一个接口返回该Map中的数据用于排查问题 ……
可以把Spring Boot Actuator当做玻璃窗能观察到运行时系统的内部情况。当然用常规的接口也能实现但不方便因为要考虑如何在鉴权框架中排出掉这些接口以及如何对此类接口进行管理这就不能像Spring Boot Actuator这样得心应手——Spring Boot Actuator可以通过配置文件来控制。
总结
本文介绍了Spring Boot Actuator的简单使用