spring boot 2.0访问actuator endpoints 404问题

在spring boot 2.0 之后访问/metrics,/routes等端点,一直返回404。访问/actuator端点查看,发现只有health和info的信息。

{
    "_links": {
        "self": {
            "href": "http://localhost:8081/actuator",
            "templated": false
        },
        "health": {
            "href": "http://localhost:8081/actuator/health",
            "templated": false
        },
        "info": {
            "href": "http://localhost:8081/actuator/info",
            "templated": false
        }
    }
}

在网上查解决方案,写的五花八门。最后查看官方文档,发现了问题:

每个actuator端点(endpoint)都有enable和exposed两个属性:如果想要通过HTTP访问他们,就需要两个属性均为true。

默认情况下:

  1. 只有/health和/info的exposed是true
  2. 除了/shutdown其他所有的端点都是enable。

我们可以通过在spring boot 配置文件中配置management.endpoints.web.exposure.include的属性来管理各个端点:

  • 选择若干个要开启的端点。
    management.endpoints.web.exposure.include=["auditevents","health","info"]

  • 开启全部端点:
    management.endpoints.web.exposure.include=*

    在yaml中,需要加上""
    management.endpoints.web.exposure.include="*"

  • 如果想要enable /shutdown端点:
    management.endpoint.shutdown.enabled=true

  • 如果想要暴露所有enable的web端点除了env:
    management.endpoints.web.exposure.include=*
    management.endpoints.web.exposure.exclude=env

参考spring boot github wiki

你可能感兴趣的:(Java,spring,boot)