此链接Writing_custom_healthindicators描述如何注册自定义,HealthIndicators
以便它们可以与Spring Boot Actuator一起使用。链接中的示例@Component
用于注册实现该HealthIndicator
接口的自定义类。
但是我正在创建匿名HealthIndicator
实例。以下是如何HealthIndicators
创建这些匿名实例的示例。
HealthIndicator healthIndicator = () -> {
Health h;
//custom code to instantiate Health object.
return h;
};
//how to register h with Spring?
可以说,上面的代码在for循环中,其中HealthIndicators
正在创建许多循环。如何在Spring中注册它们,以便Spring Boot Actuator如链接中所述识别它们?
一种方法是HealthEndpoint
像这样提供自定义:
@Configuration
class HealthConfig {
@Bean
HealthEndpoint healthEndpoint(Map<String, HealthIndicator> defaultIndicators){
for(int i=0;i<10;i+=1){
defaultIndicators.put("custom_indicator_" + i, ()-> Health.down().build());
}
return new HealthEndpoint(new OrderedHealthAggregator(), defaultIndicators);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句