Spring Boot - Change the location of the /health endpoint to /ping/me
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.
Related videos on Youtube
![Nagendra Kakarla](https://lh5.googleusercontent.com/-z8o2iOFxuxg/AAAAAAAAAAI/AAAAAAAALcs/G61iQPQKhJM/photo.jpg?sz=256)
Nagendra Kakarla
Updated on June 12, 2022Comments
-
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 over 8 yearsIt did not help. The application throws binding errors
-
Ali Dehghani over 8 yearsDid you use the
/ping/me
? It's still anid
, you can not use the/
inid
-
Nagendra Kakarla over 8 yearsSetting 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 over 8 years@Nagendra Kakarla you can use this feature in
1.3.3.RELEASE
version. -
Manikandan about 6 yearsHelped me to change the actual actuator health check url. Thanks.