如何在 spring boot + cloud 中禁用 refreshScope 运行状况指示器?
How can I disable the refreshScope health indicator in spring boot + cloud?
我已经使用 health.config.enabled=false
禁用了配置服务器健康指示器,但这并没有禁用 refreshScope 健康指示器。
使用:
management.health.refresh.enabled=false
您需要创建一个 RefreshScopeHealthIndicator
的 bean 并覆盖 doHealthCheck
方法以不抛出异常。代码片段是 Kotlin,但你会明白的。
@Component
class CustomHealthIndicator(
private val scope: ObjectProvider<RefreshScope>,
private val rebinder: ConfigurationPropertiesRebinder
): RefreshScopeHealthIndicator(scope, rebinder) {
override fun doHealthCheck(builder: Health.Builder) {
builder.up()
}
}
我已经使用 health.config.enabled=false
禁用了配置服务器健康指示器,但这并没有禁用 refreshScope 健康指示器。
使用:
management.health.refresh.enabled=false
您需要创建一个 RefreshScopeHealthIndicator
的 bean 并覆盖 doHealthCheck
方法以不抛出异常。代码片段是 Kotlin,但你会明白的。
@Component
class CustomHealthIndicator(
private val scope: ObjectProvider<RefreshScope>,
private val rebinder: ConfigurationPropertiesRebinder
): RefreshScopeHealthIndicator(scope, rebinder) {
override fun doHealthCheck(builder: Health.Builder) {
builder.up()
}
}