簡體   English   中英

如何使用自定義值覆蓋Spring Boot運行狀況終結點?

[英]How to override spring boot health endpoint with custom values?

我想用自定義json響應覆蓋Spring boot Health端點。 我嘗試使用public class MyHealth implements HealthIndicator但是返回了一些用myHealth對象包裝的值

這實際上是我在實施后得到的

{
  "status": "UP",
  "myHealth": {
    "name": "Integration Service",
    "version": "1.0",
    "_links": {
      "self": {
        "href": "http://localhost:8083/health"
      }
    }
  }
}

但這實際上是我想要的輸出

{
  "name": "Integration Service",
  "version": "1.0",
  "status": "UP",
  "_links": {
    "self": {
      "href": "http://localhost:8083/health"
    }
  }
}

除非您完全重寫HealthEndpoint否則您無法做到這一點。 /health端點的全部要點是,它為您提供了一個標准結構,以便您可以以一致的方式監視事物。 如果您添加了自定義的HealthIndicator它將像您已經看到的那樣被嵌套

如果要完全更改輸出格式,則可以創建自己的終結點並執行所需的任何操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM