Spring Boot的Actuator提供了运行状态监控功能,可以通过REST、远程Shell和JMX方式来查看,使用时在pom文件添加spring-boot-starter-actuator的依赖即可。
配置文件中添加如下内容即可:
management.port=9001
management.security.enabled=false
但在Spring Boot2.0中以上配置选项被废除,而改用如下配置项:
#actuator端口
management.server.port=9001
#修改访问路径 2.0之前默认是/ 2.0默认是 /actuator 可以通过这个属性值修改
management.endpoints.web.base-path=/monitor
#开放所有页面节点 默认只开启了health、info两个节点
management.endpoints.web.exposure.include=*
#显示健康具体信息 默认不会显示详细信息
management.endpoint.health.show-details=always
配置完成启动项目后就可以通过postman或者直接在预览器输入路径等方式来查看应用的运行状态了。
例如使用postman发送localhost:9001/monitor/healthGET请求.
本文详细介绍如何在SpringBoot项目中使用Actuator模块进行运行状态监控。从添加依赖到配置端口、路径及开放节点,再到展示健康详情,一步步引导读者实现应用监控。
4539

被折叠的 条评论
为什么被折叠?



