java如何在Spring引导执行器中注册匿名HealthIndicators
这个链接writing_custom_healthindicators描述了如何注册自定义HealthIndicators
,以便它们可以与弹簧引导执行器一起使用。链接中的示例使用@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引导执行器能够识别链接中提到的它们
# 1 楼答案
一种方法是提供自定义^{} ,如下所示: