简体   繁体   中英

How to override spring boot health endpoint with custom values?

I want to override the Spring boot Health endpoint with custom json response. I tried with public class MyHealth implements HealthIndicator but that was return some values wrap with myHealth object

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 . 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. If you add a custom HealthIndicator it's going to be nested as you've seen yourself already.

If you want to completely change the output format, you can create your own endpoint and do whatever you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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