Punter Vicky
Punter Vicky

Reputation: 17032

Disabling custom health check endpoints

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?

Upvotes: 2

Views: 9206

Answers (2)

Mark Bramnik
Mark Bramnik

Reputation: 42541

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.

Upvotes: 2

Koustav Ray
Koustav Ray

Reputation: 1142

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

Upvotes: 1

Related Questions