Update: @Thierry mentioned @AutoConfigureMetrics is deprecated and one needs to use the @AutoConfigureObservability annotation instead. See his post!
Original post:
I faced the same issue. After some tracing through spring-context ConditionEvaluator, I found that the newly introduced @ConditionalOnEnabledMetricsExport("prometheus")
condition on PrometheusMetricsExportAutoConfiguration
prevented the endpoint from loading.
This is intended behavior due to https://github.com/spring-projects/spring-boot/pull/21658 and impacts spring-boot 2.4.x
Fix:
add @AutoConfigureMetrics to your test
@AutoConfigureMetrics
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class IntegrationTest {