前言
Actuator 是 Spring Boot 提供的对应用系统的自省和监控的集成功能,可以查看应用配置的详细信息,例如自动化配置信息、创建的 Spring beans 以及一些环境属性等。
pom.xml文件
引入web和actuator依赖,web依赖是必须引入的,否则不能启动。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| <dependencies> <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>
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies>
|
配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| info: app: name: spring-boot-actuator-test version: 1.0.0 test: test
management: endpoints: web: base-path: /monitor exposure: include: '*' exclude: env,beans
endpoint: health: show-details: always shutdown: enabled: true
health: redis: enabled: false
|
测试
- 访问 http://localhost:8080/monitor 。默认路径为/actuator/*,配置中已经修改为base-path: /monitor。

- 访问http://localhost:8080/monitor/info 。 返回配置文件中info的内容。

- 访问http://localhost:8080/monitor/health 。显示 health 的细节。

- 访问http://localhost:8080/monitor/shutdown (post请求)。关闭 Spring Boot。

参考内容
使用 Spring Boot Actuator 监控应用
Spring Boot Actuator 使用