【问题标题】:Spring Boot - Change the location of the /health endpoint to /ping/meSpring Boot - 将 /health 端点的位置更改为 /ping/me
【发布时间】:2016-05-29 16:19:03
【问题描述】:

我将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"
}

【问题讨论】:

    标签: spring spring-boot spring-boot-actuator health-monitoring


    【解决方案1】:

    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 中已弃用。

    【讨论】:

    • 帮我更改了实际的执行器健康检查 url。谢谢。
    【解决方案2】:

    请参阅下面的 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(...) 正在为HealthEndpoint 返回false。也许这是一个错误或什么的。

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

    【讨论】:

    • 它没有帮助。应用程序抛出绑定错误
    • 你用过/ping/me吗?还是id,不能在id中使用/
    • 将 id 设置为“ping”并且路径设置为“ping”有效。但我不能指定像“ping-me”这样的连字符。我根据 spring boot docs 中的文档进行了尝试:“例如,要将 /health 端点的位置更改为 /ping/me,您可以设置 endpoints.health.path=/ping/me”
    • @Nagendra Kakarla 您可以在1.3.3.RELEASE 版本中使用此功能。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-01
    • 2019-02-03
    • 2019-08-05
    • 2019-03-10
    • 1970-01-01
    • 2018-06-18
    相关资源
    最近更新 更多