首页 > 解决方案 > Spring Boot 2 Actuator /health端点在使用身份验证时不显示其他信息

问题描述

我正在将项目从 Spring Boot 1.X 迁移到 Spring Boot 2.X。唯一剩下的给我带来麻烦的是 Spring Boot Actuator。

在 Spring Boot 1.X 中,当您使用凭据点击/health端点时,您通常会收到更详细的指标列表,例如默认org.springframework.boot.actuate.health.DiskSpaceHealthIndicator的结果。

{ "status": "UP", "diskSpace": { "status": "UP", "total": 1000240963584, "free": 909162590208, "threshold": 10485760 } }

我也会在这里看到自定义定义的健康指标。

现在我使用了较新版本的 Actuator 库,我不再收到附加信息(在提供凭据时)。我所看到的是:

{ "status": "UP" }

起初我以为我可能没有正确设置凭据,但是通过故意提供无效凭据我得到401 Unauthorized。所以它不能是身份验证。

我对调试器进行了更深入的研究,发现实际上创建了DiskSpaceHealthIndicator bean 以及我的所有其他自定义指标。但似乎它们没有被 Spring Boot 注册,让我在点击/health端点时看不到它们。

有什么建议么?

标签: javaspring-bootspring-boot-actuatorhealth-monitoring

解决方案


通过添加以下内容解决了该问题:

management.endpoint.health.show-details=when_authorized

正如@ValentinCarnu 建议的那样。

这就是我后来在文档中发现的:https ://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html#production-ready-health

默认值为从不。当用户处于一个或多个端点角色时,他们被认为是被授权的。如果端点没有配置角色(默认),则所有经过身份验证的用户都被认为是授权的。可以使用 management.endpoint.health.roles 属性配置角色。

谢谢!


推荐阅读