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

21
我将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"
}
2个回答

40

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处可用。

Spring Boot 2.0.0中弃用了endpoints.*这样的属性。


2
帮助我更改了实际执行器健康检查的URL。谢谢。 - Manikandan

10
请看下面关于Spring Boot 2.*的内容:

请参考以下链接: https://dev59.com/m1sW5IYBdhLWcg3wDzgu#50364513


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

由于isGenericEndpoint(...)对于HealthEndpoint返回false,因此拒绝设置endpoints.health.path。也许这是一个bug或其他什么原因。

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


没有帮助。应用程序抛出绑定错误。 - Nagendra Kakarla
你使用了/ping/me吗?它仍然是一个id,你不能在id中使用/ - Ali Dehghani
将id设置为“ping”,路径设置为“ping”是有效的。但是我无法指定连字符,例如“ping-me”。我根据Spring Boot文档中的说明尝试了这个操作:“例如,要将/health端点的位置更改为/ping/me,您可以设置endpoints.health.path=/ping/me”。 - Nagendra Kakarla
@Nagendra Kakarla,您可以在1.3.3.RELEASE版本中使用此功能。 - Ali Dehghani

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接