在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。
默认情况下:
- 只有/health和/info的exposed是true
- 除了/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

解决SpringBoot 2.0后/metrics等端点访问返回404问题,需在配置文件中设置management.endpoints.web.exposure.include属性,正确管理各端点的启用与暴露状态。
2万+

被折叠的 条评论
为什么被折叠?



