Play+Spring应用集成Prometheus访问/actuator/prometheus返回404求助
排查解决步骤
- 配置加载验证
Play框架默认使用application.conf,但Spring Boot原生默认读取application.yml/application.properties配置源,首先确认Spring上下文是否正确读取到了management.endpoints.web.exposure.include="prometheus"配置:可以在Spring托管的Bean中注入@Value("${management.endpoints.web.exposure.include:}")打印值校验。如果未读取到,可将该配置迁移到Spring识别的配置文件中,或配置Play配置源同步到Spring上下文。 - 依赖版本兼容性校验
Spring Boot 2.2.4.RELEASE官方适配的Micrometer版本为1.3.x系列,你当前使用的micrometer-registry-prometheus:1.2.0存在版本兼容风险,可能导致端点注册失败。建议移除该依赖的版本号,由Spring Boot依赖管理自动适配对应版本,或手动升级到1.3.x匹配版本。 - 路由与路径配置校验
- 检查是否自定义了Actuator根路径:若配置了
management.endpoints.web.base-path,需将访问路径的/actuator替换为自定义的根路径值 - 混合架构路由校验:Play+Spring架构下请求默认由Play路由规则优先处理,需确认Play路由配置中是否将
/actuator/**路径的请求转发到Spring的DispatcherServlet,若Play未配置对应转发规则,会直接返回404。
- 检查是否自定义了Actuator根路径:若配置了
- 端点开启状态校验
如果存在全局关闭Actuator端点的配置management.endpoints.enabled-by-default=false,需要额外添加配置management.endpoint.prometheus.enabled=true手动开启Prometheus端点。 - 启动日志校验
查看服务启动日志,搜索关键词endpoint,正常注册成功会打印类似Exposing 1 endpoint(s) beneath base path '/actuator'的日志,若日志中未包含prometheus端点,可向上检索相关依赖加载、类初始化的异常信息定位问题。
内容的提问来源于stack exchange,提问作者Deepa Khanna
相关产品推荐
相关产品推荐

