springspring-boot

Is it possible to deactivate MongoHealthIndicator in the Springboot spring actuator health endpoint?


In the springboot project that I work on there is a transitive maven dependency on spring-data-mongodb. Therefore the MongoHealthIndicator seems to be activated automatically although the project does not actually use mongodb. Is it possible to deactivate specifically this HealthIndicator without deactivating the actuator health endpoint? A workaround that I found is excluding the dependency. But I was wondering if it is possible to do this specific deactivation of the MongoHealthIndicator.


Solution

  • From common application properties:

    # HEALTH INDICATORS (previously health.*)
    ...
    management.health.mongo.enabled=true
    ...
    

    You should be able to set that to false to disable the health indicator. From org.springframework.boot.actuate.autoconfigure.HealthIndicatorAutoConfiguration.java

    @Configuration
    @ConditionalOnBean(MongoTemplate.class)
    @ConditionalOnProperty(prefix = "management.health.mongo", name = "enabled", matchIfMissing = true)
    public static class MongoHealthIndicatorConfiguration {