ERK
ERK

Reputation: 406

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"
    }
  }
}

Upvotes: 1

Views: 2156

Answers (1)

Stephane Nicoll
Stephane Nicoll

Reputation: 33151

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.

Upvotes: 1

Related Questions