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

Spring Boot 3.0+WebFlux环境下如何配置Prometheus端点?

Spring Boot 3 + WebFlux + Netty 配置Prometheus端点404问题排查

以下是你可能遗漏的关键配置和步骤:

1. 显式暴露Prometheus端点

Spring Boot 3中Actuator默认仅暴露health和info端点,必须手动配置暴露prometheus:

# application.yml
management:
  endpoints:
    web:
      exposure:
        include: prometheus,health

或properties格式:

# application.properties
management.endpoints.web.exposure.include=prometheus,health

2. 注意端点路径变更

Spring Boot 3的Actuator默认基础路径为/actuator,不再使用旧版本的/metrics路径。正确的Prometheus指标路径是:
http://<host>:<port>/actuator/prometheus

3. WebFlux环境的路由冲突检查

如果项目是纯WebFlux架构(未引入spring-boot-starter-web),检查是否有自定义路由配置拦截了/actuator/**路径,确保该路径未被自定义路由覆盖。

4. Spring Security权限放行(若启用)

如果项目启用了Spring Security,需在WebFlux的安全配置中放行Actuator端点:

@Configuration
public class SecurityConfig {
    @Bean
    public SecurityWebFilterChain securityWebFilterChain(ServerHttpSecurity http) {
        return http
                .authorizeExchange(exchanges -> exchanges
                        .pathMatchers("/actuator/**").permitAll()
                        .anyExchange().authenticated()
                )
                .build();
    }
}

5. 启动日志验证

启动应用后查看控制台日志,确认Prometheus端点已注册:

日志中应包含类似 Exposing X endpoint(s) beneath base path '/actuator' 的内容,且其中明确列出prometheus

完成以上配置后,重新启动应用,访问/actuator/prometheus即可获取Prometheus格式的指标数据。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 19:15:56