Spring Boot - 将/ health端点的位置更改为/ ping/me

Nag*_*rla 8 spring health-monitoring spring-boot spring-boot-actuator

我将endpoints.health.path属性设置为/ping/me.但我无法使用http:// localhost:9000/ping/me访问端点 它只适用于http:// localhost:9000/health.我错过了什么?这是app属性文件中的代码.

#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
Run Code Online (Sandbox Code Playgroud)

我得到的回应是:

{
"timestamp" : 1455736069839,
"status" : 404,
"error" : "Not Found",
"message" : "Not Found",
"path" : "/ping/me"
}
Run Code Online (Sandbox Code Playgroud)

Vla*_*sev 18

Actuator在Spring Boot 2.0.0中与技术无关,因此它现在与MVC无关.因此,如果您使用Spring Boot 2.0.x,则只需添加以下配置属性:

# 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
Run Code Online (Sandbox Code Playgroud)

如果您不覆盖management.endpoints.web.base-path,您的健康检查将在/actuator/ping/me.

类似的属性endpoints.*在Spring Boot 2.0.0中已被弃用.

  • 帮助我更改实际执行器运行状况检查 url。谢谢。 (2认同)

Ali*_*ani 6

参见下面的Spring Boot 2. * /sf/answers/3525515941/


MvcEndpoints负责读取endpoints.{name}.path配置及其afterPropertiesSet方法:

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);
            }
}
Run Code Online (Sandbox Code Playgroud)

endpoints.health.path由于isGenericEndpoint(...)返回false,它拒绝设置HealthEndpoint。也许是错误或其他。

更新:显然这是一个错误,并已在1.3.3.RELEASE版本中修复。因此,您可以/ping/me在此版本中将用作健康监控路径。