Spring Boot uses HealthAggregatorto combine all statuses from individual health indicators into a single whole for the entire application. You can attach a custom aggregator that delegates the default boot aggregator OrderedHealthAggregator, and then maps UPto HAPPY:
@Bean
public HealthAggregator healthAggregator() {
return new HappyHealthAggregator(new OrderedHealthAggregator());
}
static class HappyHealthAggregator implements HealthAggregator {
private final HealthAggregator delegate;
HappyHealthAggregator(HealthAggregator delegate) {
this.delegate = delegate;
}
@Override
public Health aggregate(Map<String, Health> healths) {
Health result = this.delegate.aggregate(healths);
if (result.getStatus() == Status.UP) {
return new Health.Builder(new Status("HAPPY"), result.getDetails())
.build();
}
return result;
}
}
If you want to completely control the response format, you will need to write your own MVC endpoint implementation. You can use an existing class HealthMvcEndpointin Spring Boot as a superclass and override its method invoke.
source
share