スプリングブートはHealthAggregator
を使用して、個々のヘルスインジケータのすべてのステータスをアプリケーション全体の単一の状態に集約します。あなたは、ブートのデフォルトのアグリゲータ、OrderedHealthAggregator
にその委任するカスタムアグリゲーターをプラグインし、その後HAPPY
にUP
をマップすることができます。
@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;
}
}
あなたはレスポンスのフォーマットを完全に制御をしたい場合は、あなたがする必要があります独自のMVCエンドポイント実装を記述します。 Springブートで既存のHealthMvcEndpoint
クラスをスーパークラスとして使用し、そのinvoke
メソッドをオーバーライドすることができます。
実際、これは私の質問には答えません。これはまだJSON構造体を返します。私はプレーンテキストの文字列 "HAPPY"とそれ以外は必要ありません。このaggregate()はHealthオブジェクトを返すため、これを行う方法はありません。健康と状態はどちらも最終的なので、私はその行動をカスタマイズする方法がわかりません。 – donahchoo