18

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

#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

我得到的回应是:

{
"timestamp" : 1455736069839,
"status" : 404,
"error" : "Not Found",
"message" : "Not Found",
"path" : "/ping/me"
}
4

2 回答 2

34

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

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

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

于 2018-05-16T07:13:09.783 回答
7

请参阅下面的 Spring Boot 2.* https://stackoverflow.com/a/50364513/2193477


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);
            }
}

它拒绝设置endpoints.health.path, 因为isGenericEndpoint(...)正在返回falsefor HealthEndpoint。也许这是一个错误或什么的。

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

于 2016-02-17T20:15:36.227 回答