禁用自定义健康检查端点

huangapple go评论90阅读模式
英文:

Disabling custom health check endpoints

问题

SpringBoot提供了一种类似于以下方式的禁用健康检查端点的方法:

management.health.mongo.enabled=false

是否有一种方法可以禁用我通过实现HealthIndicator接口创建的自定义健康检查端点?

英文:

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?

答案1

得分: 2

以一个MongoDB健康指标为例:

它在类中定义:org.springframework.boot.actuate.autoconfigure.mongo.MongoHealthIndicatorAutoConfiguration(详见源代码

看起来像是常规配置,带有自定义条件:

@ConditionalOnEnabledHealthIndicator("mongo")

现在,这是一个内部的Spring Boot执行器注解,基本上是一个自定义的条件属性,

由于您的自定义健康检查本身就是一个Bean,将其注册到此条件(@ConditionalOnEnabledHealthIndicator("whatever"))中,只要存在一个属性:

management.health.whatever.enabled=false

如果您想要不遵循此标准的自定义属性,您可以使用@ConditionalOnProperty,这已经是其他人在这里建议过的。

英文:

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.

答案2

得分: 1

Sure, here's the translated code snippet:

你能提供一下你是如何实现自定义端点的代码片段吗
也许可以使用 `@ConditionalOnProperty`,就像 @Seb 提到的那样可以参考这个链接
https://stackoverflow.com/a/26403131/4875624
英文:

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

huangapple
  • 本文由 发表于 2020年7月27日 22:08:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/63117112.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定