Spring Boot 2执行器/健康端点在使用身份验证时未显示其他信息



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

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

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

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

现在我使用了执行器库的新版本,我不再收到额外的信息(在提供凭据时)。我看到的只是:

{ "status": "UP" }

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

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

有什么建议吗?

通过添加以下内容修复了问题:

management.endpoint.health.show-details=when_authorized

正如@ValentinCarnu所建议的那样。

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

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

谢谢!

不要使用此URLhttp://localhost:8080/env请改用http://localhost:8080/actuator/env

并使用以下设置Application.properties

management.security.enabled=false management.endpoints.web.exposure.include=*

为我工作

最新更新