java - 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端点时看不到它们。
有什么建议么?
解决方案
通过添加以下内容解决了该问题:
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 属性配置角色。
谢谢!
推荐阅读
- elasticsearch - 即使有 0 个未分配的分片,Elasticsearch 集群状态仍为黄色
- foreign-keys - 从查找字段中获取用户友好的值
- javascript - 使用 Javascript 验证表单输入
- javascript - 如何在 TypeScript 中导入 JavaScript 模块并转换为 TypeScript 命名空间
- ruby-on-rails-5 - 如何在部署中更新 Rails 5.2 凭据和主密钥
- python - 使用 Python setup.py 通过 develop 与 install 安装不同的依赖项
- sql - 添加两个查询一起使用
- python - 使用 Python 提取准确的价格数据,如在 Excel 表中看到的那样,而不用四舍五入 Python 端的值
- multithreading - Async/Await 仍然阻塞 UI?
- c - 为什么我会收到“free(): invalid pointer”的错误?