我已经创建了一个Spring Boot Actuator端点,我需要将一些信息从该端点传递到我已实现的自定义健康指标之一。下面的代码段是我的终点。现在假设我在调用此端点时传递了一个字符串作为标头。现在,我希望将此标头依次传递到我创建的自定义健康点。我该如何实现?
据我了解,HealthEndpoint
包含有关弹簧执行器默认提供的健康指标以及我们实施的自定义健康指标的信息。
@Component
@Endpoint(id = "healthcheck")
public class HealthCheckEndpoint {
private final HealthEndpoint healthEndpoint;
@Autowired
public HealthCheckEndpoint(HealthEndpoint healthEndpoint) {
this.healthEndpoint = healthEndpoint;
}
@ReadOperation(produces = "application/json")
public Health getHealthJson() {
Health health = healthEndpoint.health();
// Pass some information to one of the custom health indicators.
return health;
}
}
您可以使用@RequestHeader批注从请求中获取标头值。
import org.springframework.web.bind.annotation.RequestHeader;
@ReadOperation(produces = "application/json")
public Health getHealthJson(@RequestHeader(value = "customHeader") String customHeader) {
Health health = healthEndpoint.health();
// Pass some information to one of the custom health indicators.
return health;
}