Spring Boot Actuator端点通过 JMX 和HTTP 公开暴露给外界访问,大多数时候我们使用基于HTTP的Actuator端点,因为它们很容易通过浏览器、CURL命令、shell脚本等方式访问。
一些有用的执行器端点是:
/beans:此端点返回应用程序中配置的所有bean的列表。
/env:提供有关Spring Environment属性的信息。
/health:显示应用程序运行状况
/info:显示应用程序信息,我们可以在Spring环境属性中配置它。
/mappings:显示所有 @RequestMapping 路径 的列表 。
/shutdown:允许我们正常关闭应用程序。
/threaddump:提供应用程序的线程转储。
启用Spring Actuator端点
当我们将Spring Actuator Dependencies添加到我们的Spring启动项目时,它会自动启用执行器端点。将以下依赖项添加到Spring应用程序以启用Spring启动执行器端点。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
默认开放:
/actuator/info
/actuator/health
暴露端点
management:
endpoint:
health:
show-details: always
endpoints:
web:
exposure:
include: "*"
自定义执行器端点基本路径
默认情况下,执行器端点的基本路径是 /actuator ,我们可以通过 management.endpoints.web.base-path 在应用程序属性文件中 设置将其更改为任何其他值 。
management:
endpoints:
web:
base-path: '/monitor'
要仅启用特定的执行器端点,请提供端点ID列表。
management:
endpoints:
web:
exposure:
include: "health,info,beans,env"
推荐chrome插件:
JSON formatter: 自动格式化返回的json串
网友评论