Spring Boot有四大神器,分别是auto-configuration、starters、cli、actuator,本文主要讲actuator。
actuator是spring boot提供的对应用系统的自省和监控的集成功能,可以对应用系统进行配置查看、相关功能统计等。 Actuator 的监控数据可以通过阻REST 、远程shell 和JMX方式获得。本文只介绍REST方式。
本文基于spring boot 2.0 以上版本,相对较低版本actuator变化较大,请读者注意。
1、开启Actuator
在pom文件中引入Actuator的起步依赖spring-boot-starter-actuator.
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> <scope>test</scope> </dependency>
2、修改配置application.yml文件
这两个配置分别配置了Actuator 对外暴露REST API 接口的端口号和Actuator 采取非安全验证方式
Spring Boot Actuator 的关键特性是在应用程序里提供众多