2

SpringBoot offers a way to disable health check endpoints similar to below

management.health.mongo.enabled=false

Is there a way to disable a custom health check endpoint which I have created by implementing HealthIndicator interface?

Punter Vicky
  • 15,954
  • 56
  • 188
  • 315
  • 1
    I am not aware of any healthcheck-specific mechanism here, but what about using @ConditionalOnProperty? https://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/autoconfigure/condition/ConditionalOnProperty.html – Seb Jul 27 '20 at 14:18

2 Answers2

2

Take for example a mongo health indicator:

Its defined in class: org.springframework.boot.actuate.autoconfigure.mongo.MongoHealthIndicatorAutoConfiguration (see the source-code)

And looks like a regular configuration with a custom conditional on it:

@ConditionalOnEnabledHealthIndicator("mongo")

Now this is an internal spring boot actuator's annotation that is basically a custom conditional on property,

Since your custom healthcheck is a bean itself, registering it with this conditional (@ConditionalOnEnabledHealthIndicator("whatever")) will NOT pick your healthcheck as long as there is a property:

management.health.whatever.enabled=false

If you want the custom property that doesn't follow this standard you can use @ConditionalOnProperty as was already suggested by other people here.

Mark Bramnik
  • 39,963
  • 4
  • 57
  • 97
1

Can you provide the code snippet on how you have implemented the custom endpoint? Maybe @ConditionalOnProperty can help as suggested by @Seb. Have a look at this: https://stackoverflow.com/a/26403131/4875624

Koustav Ray
  • 1,112
  • 13
  • 26