You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot Actuator仅暴露1个端点,如何配置health与metrics双端点?

问题分析与解决

你遇到的核心问题是缺少Spring Boot Actuator的核心依赖,导致metrics端点无法被正确加载。

问题原因

你的pom.xml中仅引入了spring-boot-starter-web,但没有添加Actuator的starter依赖。Actuator的metrics等端点属于独立功能模块,必须显式引入对应依赖才能生效。

解决步骤

在pom.xml中添加spring-boot-starter-actuator依赖:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

验证

添加依赖后重新启动应用,控制台会显示:

Exposing 2 endpoint(s) beneath base path '/actuator'

此时访问http://localhost:8090/actuator/metrics即可正常获取指标数据,/actuator/health也能正常访问。

补充说明

你的application.properties配置是正确的:

  • management.endpoints.enabled-by-default=true确保默认端点开启
  • management.endpoints.web.exposure.include=health,metrics指定暴露的端点
  • management.endpoint.metrics.enabled=true单独确认metrics端点开启
    这些配置在添加Actuator依赖后就能正常生效。

内容的提问来源于stack exchange,提问作者lm.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 23:07:04