【SpringBoot】通过actuator查看应用程序中有哪些bean

318 阅读1分钟

持续创作,加速成长!这是我参与「掘金日新计划 · 10 月更文挑战」的第9天,点击查看活动详情

操作步骤

  1. 创建SpringBoot应用时,引入actuator依赖
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
  1. application.properties配置文件中添加一行配置 management.endpoints.web.exposure.include=*( ⽣产环境需谨慎 )

  1. 访问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=*。 ( ⽣产环境需谨慎 )