Spring Boot 2.0.0中/actuator/prometheus端点无法暴露求助
Hey there, let's work through why your /actuator/prometheus endpoint isn't accessible even with management.endpoints.web.exposure.include=* configured. This is a common gotcha in Spring Boot 2.0.x, so here are the key checks to fix it:
First, confirm you have the required dependency
Spring Boot 2.0.0 doesn't include the Prometheus registry out of the box. The/actuator/prometheusendpoint only becomes available when you add themicrometer-registry-prometheusdependency to your build. Make sure it's present:For Maven:
<dependency> <groupId>io.micrometer</groupId> <artifactId>micrometer-registry-prometheus</artifactId> <version>1.0.6</version> <!-- Matches Spring Boot 2.0.0's compatible Micrometer version --> </dependency>For Gradle:
implementation 'io.micrometer:micrometer-registry-prometheus:1.0.6'Check your actuator base path
If you've modifiedmanagement.endpoints.web.base-path(e.g., set it to/manage), your Prometheus endpoint will be at{base-path}/prometheusinstead of/actuator/prometheus. Double-check this configuration property to ensure you're hitting the right URL.Verify security settings aren't blocking the endpoint
If you're using Spring Security, it might be restricting access to actuator endpoints. Add a rule to allow unauthenticated access to/actuator/prometheusin your security configuration:@Configuration public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/actuator/prometheus").permitAll() .anyRequest().authenticated(); } }Even if you don't have explicit Spring Security config, Spring Boot 2.0.0 enables basic security for actuators by default. You can disable this temporarily (for testing) with:
management.security.enabled=falseCheck startup logs for clues
Fire up your app and search the logs for "prometheus". If you don't see any lines indicating the endpoint is being registered, that's a strong sign the dependency is missing or misconfigured.
Start with adding the micrometer dependency—it's the most frequent fix for this issue in Spring Boot 2.0.0. If that doesn't work, move through the other checks one by one.
内容的提问来源于stack exchange,提问作者Teruyuki Takazawa

