列出 2025 年默认开放的 5 个 actuator 端点及其返回格式

解读

国内大厂面试常把“默认”二字作为陷阱:候选人若只背 2.x 的旧列表,会漏掉 3.2 之后默认仅 Web 暴露的变动。回答时必须先给出2025 年 Spring Boot 3.2.x 官方默认暴露的 5 个端点,再分别说明它们开箱即用的返回格式(Content-Type + 典型字段),才能体现“版本敏感”与“生产落地”意识。

知识点

  1. 端点暴露规则:
    • 3.2 起 management.endpoints.web.exposure.include=health,info,metrics,env,loggers
    • 其余如 shutdown、beans、heapdump 需手动 include
  2. 返回格式:
    • 默认仅 JSON(除非主动引入 spring-boot-actuator-docs 或 HAL 探索)
    • 时间、内存单位统一使用小写缩写(s、ms、bytes)
  3. 安全合规:
    • 国内等保 2.0 要求敏感端点必须走内部端口或加网关鉴权,面试时可顺带提及

答案

2025 年 Spring Boot 3.2 在 Web 层默认仅开放以下 5 个端点:

  1. /actuator/health
    Content-Type: application/vnd.spring-boot.actuator.v3+json
    返回示例:
    {"status":"UP","components":{"diskSpace":{"status":"UP","details":{"total":21474836480,"free":10240000000,"threshold":10485760}},"ping":{"status":"UP"}}}

  2. /actuator/info
    Content-Type: application/vnd.spring-boot.actuator.v3+json
    返回示例:
    {"app":{"name":"order-service","version":"1.3.0","desc":"订单中心"}}
    (内容来自 info.* 配置或 InfoContributor)

  3. /actuator/metrics
    Content-Type: application/vnd.spring-boot.actuator.v3+json
    返回示例:
    {"names":["jvm.memory.used","http.server.requests","system.cpu.usage"]}

  4. /actuator/metrics/{metric.name}
    同上 Content-Type
    示例 .../metrics/http.server.requests:
    {"name":"http.server.requests","description":"HTTP 请求统计","baseUnit":"milliseconds","measurements":[{"statistic":"COUNT","value":168}],"availableTags":[{"tag":"uri","values":["/api/order/**"]}]}

  5. /actuator/env
    Content-Type: application/vnd.spring-boot.actuator.v3+json
    返回示例:
    {"activeProfiles":["prod"],"propertySources":[{"name":"application-prod.yml","properties":{"server.port":{"value":8080}}}]}

注意:loggers 端点虽在默认 include 列表,但仅支持 GET/POST 方法交互,返回也是 JSON,不过多数面试官把“5 个”理解为最常用只读场景,因此上面 5 个足以覆盖。

拓展思考

  1. 如果面试官追问“如何关闭默认端点又不改代码”,可答:
    在 k8s ConfigMap 里加 management.endpoints.web.exposure.exclude=* 并滚动重启,满足运维零侵入要求。
  2. 若问“返回格式能否自定义为 XML”,可答:
    3.x 已移除官方 XML 支持,需自己实现 HttpMessageConverter<HealthComponent> 并注册到 WebMvcConfigurer,但国内主流仍用 JSON 方便接入 Prometheus + Grafana。
  3. 等保场景下,建议把 env、heapdump 等端点绑定到独立管理端口(management.server.port=8081)并加网关鉴权,这样可在面试中展示安全合规意识,拉开与普通候选人的差距。