SandDev
SandDev

Reputation: 86

Spring boot disable Custom HealthIndicator

I've created a custom HealthIndicator which I wants to disable in production until we go live fully. I'm aware there is a property to disable default health indicators (management.health.defaults.enabled=false), but not for custom HealthIndicators.

Is there any way I can temporarily turn off MyCustomHealthIndicator in application property configuration level?

Upvotes: 2

Views: 6294

Answers (3)

user2324329
user2324329

Reputation: 1

@ConditionalOnEnabledHealthIndicator("your-health")

You can now disable your own health indicator by using the Spring Boot suggested property:

management.health.your-health.enabled=false

This works when we re-start the app. should it work without re-start?

Upvotes: 0

Rob Spoor
Rob Spoor

Reputation: 9100

You can use Spring Boot's mechanism without using custom properties. Start by adding an annotation on your class:

@ConditionalOnEnabledHealthIndicator("your-health")

You can now disable your own health indicator by using the Spring Boot suggested property:

management.health.your-health.enabled=false

It has the same effect, but it allows you to group your enabled and disabled health indicators together.

Upvotes: 7

aksss
aksss

Reputation: 333

Your health indicator bean,

@ConditionalOnProperty(value='health.indicator.enabled')
@Bean 
class MyHealthIndicator {
}

In your application.properties file,

health.indicator.enabled=true/false

Hope this helps !

Upvotes: 4

Related Questions