Search code examples
javakotlinframeworksjvmmicronaut

Disable mongoldb health indicator Micronaut


i want to disable health indicator for Micronaut, mi application cannot check the health for db. Im using Micronaut framework. disable health indicator im getting the

Path Taken: new HealthMonitorTask(CurrentHealthStatus currentHealthStatus,[List healthIndicators]) --> new MongoHealthIndicator(BeanContext beanContext,[HealthAggregator healthAggregator],MongoClient[] mongoClients)````

Do you know how to disable health but without getting this error? 

Solution

  • The easiest way is probably just to replace the implementation with one that always returns UP:

    @Singleton
    @Requires(beans = MongoClient.class)
    @Replaces(MongoHealthIndicator.class)
    public class MyMongoHealthIndicator implements HealthIndicator {
    
        @Override
        public Publisher<HealthResult> getResult() {
            return Publishers.just(buildStatus("mongodb"));
        }
    
        private HealthResult buildStatusUp(String name) {
            HealthResult.Builder builder = HealthResult.builder(name);
            builder.status(HealthStatus.UP);
            return builder.build();
        }
    }