资讯动态

Boot4升级后probes默认开怎么关

发布时间:2026/10/15 8:30:55 来源:尧图企业网站定制
Boot4升级后probes默认开怎么关升到 Spring Boot 4 之后有一类变化不太会红栈但运维侧会先发现没改任何探针配置/actuator/health下却多出了liveness/readiness两组K8s 清单若还按 Boot 3「默认关、要显式开」的习惯写本地 curl 和集群探针路径会对不上。第一反应往往是「谁把 health group 配开了」「是不是加了什么 starter」翻半天才发现Boot 4 Migration Guide 把liveness / readiness probes 改成了默认启用。本文只做这条probes 默认与开关清单属性全名是什么、旧键迁到哪、怎么关、怎么 curl 验收、管理端口分离时add-additional-paths怎么用、liveness 为什么不要塞外部依赖。同系列里 Flyway starter、Jackson 3 另文已写见 Boot4升后Flyway迁移不跑怎么改、Boot4升后Jackson3怎么安全迁本稿不抢主线。依据以 Spring Boot 4.0 Migration Guide §Liveness and Readiness Probes、Configuration Changelog、application-properties 附录 与 Actuator endpoints §Kubernetes Probes 为准。一、现象升完没改配置探针组突然在了现场通常长这样parent / BOM 已经是Spring Boot 4.0业务 YAML 里没有手写过 probes 相关键本地或预发 curl/actuator/health多了liveness/readiness组或直接打/actuator/health/liveness、/actuator/health/readiness有响应K8s / 运维侧对照旧文档以为「没开 probes」却发现路径已经可用——和 Boot 3「要显式开才暴露」的预期对不上。「能启、无红栈、探针路径突然可用」是值班里常见的表现。根因以 Migration Guide 为准别先猜成「谁加了 health group」或「Actuator 版本配错」。还有一种半迁移更隐蔽YAML 里仍写着 Boot 3 时代的旧键management.health.probes.enabled以为关了实际 Boot 4 已迁出该键——新默认仍是开。升级 PR 描述里把「属性是否已是新全名」和「两路径 curl 是否符合预期」拆成两行勾选比事后对集群探针清单做差分便宜。值班排障时不妨先问三句应用是不是已经 Boot 4YAML 里有没有手写 probesK8s 探针 URL 是探/actuator/health总览还是探分拆后的 liveness/readiness这三句对齐之后再决定是「接受默认开、改清单」还是「业务根本不需要探针、应用侧关 false」。顺序反了容易出现「清单已按关着写、应用仍默认开」或反过来的双端不一致。二、根因Migration Guide 明文默认开Migration Guide §Liveness and Readiness Probes 写明The liveness and readiness probes are now enabled by default. This means the health endpoint now exposes thelivenessandreadinessgroups by default.也就是说不是「多配一组可选优化」而是 Boot 4 起默认就把这两组挂到 health 上。不需要时用属性关掉——同一节给出的键就是management.endpoint.health.probes.enabled。附录 application-properties 与之一致management.endpoint.health.probes.enabled说明为 Whether to enable liveness and readiness probes默认值true。Actuator 文档 §Kubernetes Probes 再次确认这些 health groups are automatically enabled可用同一属性 disable。用一张对照流先钉死「Boot3 显式开 → Boot4 默认开 → 关闭/验收」三、属性名迁移旧键已迁出关就用新全名3.1 新键默认 true关 false关闭探针组写management:endpoint:health:probes:enabled:false或等价的 propertiesmanagement.endpoint.health.probes.enabledfalse附录默认是true设为false即 Migration Guide 说的「If you do not need those probes, you can disable them」。需要保留默认行为时可以不写该键——缺省就是开。3.2 旧键management.health.probes.enabled已 RemovedConfiguration ChangelogRemoved表写明旧名management.health.probes.enabled的 Replacement 是management.endpoint.health.probes.enabled。升完若 YAML 里还留着旧键# Boot 4 勿再当推荐键Changelog Removed# management.health.probes.enabledfalse应改成新全名。可跑 Spring Boot 配置迁移器properties migrator对照 Changelog比肉眼扫 YAML 稳。不要把旧键继续写成「当前推荐写法」。实践里建议先在配置树 / 启动 Environment 里确认生效的是management.endpoint.health.probes.enabled再谈 K8s 探针清单是否改路径。旧键没清干净之前先改 Deployment 的 probe URL很容易改出「应用侧其实仍默认开、清单却按关着写」的更难排障状态。四、怎么验两条路径 curl默认management.endpoints.web.base-path/actuator时官方暴露的 HTTP 探针路径是/actuator/health/liveness/actuator/health/readinessActuator 文档原话大意exposed as separate HTTP Probes by using health groups并给出上述两条路径。升 Boot 4、且未关 probes 时本地可这样验收端口按你的 server.port 改# 默认开两条路径应有响应具体 JSON 字段以现场 Actuator 为准curl-sShttp://localhost:8080/actuator/health/livenesscurl-sShttp://localhost:8080/actuator/health/readiness关掉后再验management.endpoint.health.probes.enabled:false# 设 false 后liveness / readiness 组按文档不再作为探针组可用# 勿死记某一固定 HTTP 状态码以你环境实测与文档为准curl-sS-o/dev/null-w%{http_code}\nhttp://localhost:8080/actuator/health/livenesscurl-sS-o/dev/null-w%{http_code}\nhttp://localhost:8080/actuator/health/readiness升级 PR 的 DoD 建议拆两行未关时两路径有响应与 K8s probe URL 一致明确不需要探针时management.endpoint.health.probes.enabledfalse且清单不再指向这两组。若你改过management.endpoints.web.base-path把路径前缀换成实际 base-path不要死记/actuator。验收时建议固定一份「升前 / 升后」对照表升前Boot 3在未显式开启时分拆探针路径往往不可用或不符合你们旧文档预期升后未关配置时两条路径应能打通。把对照结果贴进升级评论比口头说「探针好像有了」可复核。若环境开了 security 对 Actuator 鉴权curl 要带上与线上探针相同的认证方式否则会把「401/403」误判成「probes 没开」——那是安全层问题不是本文的开关键。五、边界add-additional-paths与主端口/livez/readyz当 Actuator 跑在独立 management 端口时会出现经典落差管理口上的 health 还「绿」主应用端口已经挂了。附录属性# 默认 false不在主端口额外挂探针路径 management.endpoint.health.probes.add-additional-pathsfalse设为true后官方文档说明会在主服务器端口额外暴露——liveness组对应/livezreadiness组对应/readyz这是官方默认附加路径名也可按 group 的 additional-path 自定义点到为止。management:endpoint:health:probes:enabled:trueadd-additional-paths:trueserver:port:9090# 示意management 独立端口时按你项目实际配置# add-additional-pathstrue 时主端口示意 8080上的附加路径curl-sShttp://localhost:8080/livezcurl-sShttp://localhost:8080/readyz实践上默认是 false只有「管理口与主口分离、且希望 K8s 探主口」时才打开。不要臆造其他默认路径名也不要把它和probes.enabledfalse混成同一开关。六、liveness 勿塞外部依赖Actuator §Checking External State With Kubernetes Probes 写明The “liveness” probe should not depend on health checks for external systems.外部DB、远端 HTTP、消息中间件挂了若进livenessK8s 可能整批重启实例反而放大故障面。readiness 是否包含外部检查由业务自己判断——可以更严但那是产品语义不是「默认帮你塞进探针组」。同一节还写By default, Spring Boot does not add other health indicators to these groups。也就是说Boot默认不会把磁盘、DB 等其它 indicator 自动加进liveness/readiness两组若你自定义往里塞先确认没有违反上面的 liveness 警告。一句收束即可关不关 probes 是开关问题往 liveness 里塞什么是稳定性问题——两者别搅在同一个「先改 YAML 碰运气」的 PR 里。若团队之前在 Boot 3 手工配过自定义 health group升级后先核对自定义组有没有被误当成「官方 liveness/readiness 默认组」一起改。默认两组的边界以 Actuator 文档为准自定义 group 的成员列表仍是你们自己的配置不在「probes.enabled」这一键里自动清空或自动塞入。七、常见问答Q1Spring Boot 4 为什么默认打开 liveness/readinessAMigration Guide 明文 probes are now enabled by defaulthealth 默认暴露这两组。动机侧官方按 Kubernetes 探针惯例默认打开成稿以「默认开、不需要可关」为准勿编造未给出的产品数字。Q2用哪个属性关掉 probesA全名management.endpoint.health.probes.enabled设false。附录默认true。Q3旧的management.health.probes.enabled还能用吗AChangelog 已RemovedReplacement 是新全名。升完请改键不要继续当推荐写法。Q4升 Boot4 后怎么验证 probes 路径可用A未关时 curl/actuator/health/liveness与/actuator/health/readiness相对默认 base-path关 false 后组按文档不可用。管理口分离且需要探主口时再考虑add-additional-pathstrue后的/livez/readyz。Q5关了 probes 是否等于关了整个/actuator/healthA不是。关的是 liveness/readiness探针组不要和「禁用整个 health endpoint」混为一谈。具体还暴露哪些 group以你当前management.endpoint.health.*配置为准。八、小结Boot4 上 probes 这条线可压成五步认默认Migration Guide — probesenabled by defaulthealth 默认暴露liveness/readiness。改键名旧management.health.probes.enabled已 Removed → 新management.endpoint.health.probes.enabled默认true。要关就写 false不需要探针时显式关闭需要默认行为可不写该键。验收路径curl/actuator/health/liveness与/readiness管理口分离时按需add-additional-paths→ 主端口/livez/readyz。稳住 liveness勿把 DB 等外部依赖塞进 livenessBoot 默认也不把其它 indicator 加进这两组。把「属性是否已是新全名、两路径是否与 K8s 清单一致」写进升级 DoD比事后在集群事件里猜「探针突然有/无」便宜。半迁移旧键残留或只改清单不改应用配置优先当缺陷修。落地时把「配置键与默认」和「curl / 集群探针 URL」拆两次验收一次看 Environment 里生效的属性全名一次再打两路径——混在同一巨大 PR 里容易只盯暴露清单、漏掉残留的旧management.health.probes.enabled。同系列Flyway、Jackson 3建议拆开合入。本稿只负责「默认开 / 怎么关 / 怎么验」三条可勾选。若还在用 Boot 3「显式打开 probes」手册升 4 后先改口径默认已是开清单写的是「要不要关」和「路径是否仍是 /actuator/health/liveness|readiness」而不是「要不要加一段开启配置」。

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价 →
↑