Spring Boot - Change the location of the /health endpoint to /ping/me

19,026

Solution 1

See below for Spring Boot 2.* https://stackoverflow.com/a/50364513/2193477


MvcEndpoints is responsible for reading endpoints.{name}.path configurations and somehow in its afterPropertiesSet method:

for (Endpoint<?> endpoint : delegates) {
            if (isGenericEndpoint(endpoint.getClass()) && endpoint.isEnabled()) {
                EndpointMvcAdapter adapter = new EndpointMvcAdapter(endpoint);
                String path = this.applicationContext.getEnvironment()
                        .getProperty("endpoints." + endpoint.getId() + ".path");
                if (path != null) {
                    adapter.setPath(path);
                }
                this.endpoints.add(adapter);
            }
}

It refusing from setting the endpoints.health.path, since isGenericEndpoint(...) is returning false for HealthEndpoint. Maybe it's a bug or something.

Update: Apparently this was a bug and got fixed in 1.3.3.RELEASE version. So, you can use the /ping/me as your health monitoring path in this version.

Solution 2

The Actuator became technology-agnostic in Spring Boot 2.0.0, so it's not tied to MVC now. Thus if you use Spring Boot 2.0.x, you can just add the following config properties:

# custom actuator base path: use root mapping `/` instead of default `/actuator/`
management.endpoints.web.base-path=

# override endpoint name for health check: `/health` => `/ping/me`
management.endpoints.web.path-mapping.health=/ping/me

If you don't override the management.endpoints.web.base-path, your health-check will be available at /actuator/ping/me.

The properties like endpoints.* became deprecated in Spring Boot 2.0.0.

Share:
19,026

Related videos on Youtube

Nagendra Kakarla
Author by

Nagendra Kakarla

Updated on June 12, 2022

Comments

  • Nagendra Kakarla
    Nagendra Kakarla about 2 years

    I set the endpoints.health.path property to /ping/me. But I cannot access the endpoint using http://localhost:9000/ping/me It only works with http://localhost:9000/health. What am I missing ? Here is the code in app properties file.

    #Configuration for Health endpoint
    endpoints.health.id=health
    endpoints.health.path=/ping/me
    endpoints.health.enabled=true
    endpoints.health.sensitive=false
    
    #Manage endpoints
    management.port=9000
    management.health.diskspace.enabled=false
    

    The response I get is :

    {
    "timestamp" : 1455736069839,
    "status" : 404,
    "error" : "Not Found",
    "message" : "Not Found",
    "path" : "/ping/me"
    }
    
  • Nagendra Kakarla
    Nagendra Kakarla over 8 years
    It did not help. The application throws binding errors
  • Ali Dehghani
    Ali Dehghani over 8 years
    Did you use the /ping/me? It's still an id, you can not use the / in id
  • Nagendra Kakarla
    Nagendra Kakarla over 8 years
    Setting the id to 'ping' and path to 'ping' worked. But I can't specify hyphens like 'ping-me'. I was trying this based on documentation from the spring boot docs : "For example, to change the location of the /health endpoint to /ping/me you can set endpoints.health.path=/ping/me"
  • Ali Dehghani
    Ali Dehghani over 8 years
    @Nagendra Kakarla you can use this feature in 1.3.3.RELEASE version.
  • Manikandan
    Manikandan about 6 years
    Helped me to change the actual actuator health check url. Thanks.