我编写了一个实现HealthIndicator的类,该类重写了健康方法。我回来Health.down().withDetail("SupportServiceStatus", "UP").build();
Health.down().withDetail("SupportServiceStatus", "UP").build();
这应该使我的health-endpoint返回:
health
{ "status":"UP", "applicationHealth": { "status":"UP" } }
相反,它只是返回(运行状况,没有详细信息):
{ "status":"UP", }
Javacode(有所简化):
@Component public class ApplicationHealth implements HealthIndicator { @Override public Health health() { return check(); } private Health check() { return Health.up().withDetail("SupportServiceStatus", supportServiceStatusCode).build(); } }
根据spring-boot docs:
。。。默认情况下,仅健康状态通过未经身份验证的HTTP连接公开。如果您希望始终获得完整的健康信息,则可以设置endpoints.health.sensitive为false。
endpoints.health.sensitive
false
解决方案是设置endpoints.health.sensitive为falsein application.properties。
application.properties
endpoints.health.sensitive=false
对于> 1.5.1 application.properties
management.security.enabled=false
在Spring Boot 2.0.0.RELEASE(thx @rvit34和@nisarg-panchal):
@rvit34
@nisarg-panchal
management: endpoint: health: show-details: "ALWAYS" endpoints: web: exposure: include: *
management.endpoints.web.exposure.include=* 公开所有端点(如果需要的话)。
management.endpoints.web.exposure.include=*
当前文档可以在这里找到:https : //docs.spring.io/spring-boot/docs/current/reference/html/production-ready- endpoints.html