Spring Boot 2.0.0.RC1 Webflux环境下Prometheus端点无法启用求助
解决Spring Boot Prometheus端点404的问题
别慌,咱们一步步排查解决这个问题:
1. 先确认依赖配置是否正确
你的Spring Boot版本是2.0.0.RC1,必须搭配以下两组依赖才能启用Prometheus端点:
spring-boot-starter-actuator:提供Actuator核心功能micrometer-registry-prometheus:实现Prometheus指标的导出支持
如果用Maven,在pom.xml中添加:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> </dependency>
如果用Gradle,添加到build.gradle:
implementation 'org.springframework.boot:spring-boot-starter-actuator' implementation 'io.micrometer:micrometer-registry-prometheus'
2. 修正application.yml配置
Spring Boot 2.x默认只对外暴露health和info端点,你需要显式配置暴露prometheus端点:
management: endpoints: web: exposure: include: prometheus # 如需同时暴露其他端点,用逗号分隔,比如 include: health,info,prometheus endpoint: prometheus: enabled: true # 虽然默认启用,显式配置更稳妥
如果你自定义了Actuator基础路径(比如设置management.endpoints.web.base-path: /manage),后续访问路径也要对应调整。
3. 正确的访问URL
默认情况下,Prometheus端点的访问地址是:http://<你的服务器IP>:<端口>/actuator/prometheus
如果改了基础路径,比如上面提到的/manage,则地址变为:http://<你的服务器IP>:<端口>/manage/prometheus
4. 排查其他可能的404诱因
- Spring Security拦截:如果项目集成了Spring Security,需要配置允许访问Prometheus端点,示例配置如下:
@Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/actuator/prometheus").permitAll() .anyRequest().authenticated(); }
- 版本兼容性:确保Micrometer版本和Spring Boot 2.0.0.RC1匹配(建议用1.0.0.RC1系列版本),避免版本冲突导致功能失效。
按以上步骤调整后重启应用,应该就能正常访问Prometheus端点了。
内容的提问来源于stack exchange,提问作者ROCKY
相关产品推荐
相关产品推荐

