持续创作,加速成长!这是我参与「掘金日新计划 · 10 月更文挑战」的第9天,点击查看活动详情
操作步骤
- 创建SpringBoot应用时,引入actuator依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
- application.properties配置文件中添加一行配置
management.endpoints.web.exposure.include=*( ⽣产环境需谨慎 )
- 访问http://localhost:8080/actuator/beans(具体路径由自己的配置决定)。
小tips:浏览器默认显示的json格式一般可阅读性不太友好,可以安装一下插件或扩展来辅助。比如:JSON-handle。
Actuator 提供的⼀些好⽤的 Endpoint
| URL | 作用 |
|---|---|
| /actuator/health | 健康检查 |
| /actuator/beans | 查看容器中的所有Bean |
| /actuator/mappings | 查看Web的URL映射 |
| /actuator/env | 查看环境信息 |
如何解禁 Endpoint
默认情况下Actuator的Endpoint
/actuator/health和/actuator/info可 Web 访问
解禁所有 Endpoint
- 在 application.properties 或 application.yml 文件中配置
management.endpoints.web.exposure.include=*。 ( ⽣产环境需谨慎 )