简体   繁体   English

如何使用自定义值覆盖Spring Boot运行状况终结点?

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

I want to override the Spring boot Health endpoint with custom json response. 我想用自定义json响应覆盖Spring boot Health端点。 I tried with public class MyHealth implements HealthIndicator but that was return some values wrap with myHealth object 我尝试使用public class MyHealth implements HealthIndicator但是返回了一些用myHealth对象包装的值

this is actually i got after implementation 这实际上是我在实施后得到的

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

But this is i actually i want as output 但这实际上是我想要的输出

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

You can't do that I am afraid unless you completely override the HealthEndpoint . 除非您完全重写HealthEndpoint否则您无法做到这一点。 The whole point of the /health endpoint is that it provide you a standard structure so that you can monitor things in a consistent way. /health端点的全部要点是,它为您提供了一个标准结构,以便您可以以一致的方式监视事物。 If you add a custom HealthIndicator it's going to be nested as you've seen yourself already. 如果您添加了自定义的HealthIndicator它将像您已经看到的那样被嵌套

If you want to completely change the output format, you can create your own endpoint and do whatever you want. 如果要完全更改输出格式,则可以创建自己的终结点并执行所需的任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM