我编写了一个实现 HealthIndicator 的类,覆盖了健康方法。我返回 Health.down().withDetail("SupportServiceStatus", "UP").build();
这应该让我的 health
-endpoint 返回:
{
"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 文档:
. . . by default, only the health status is exposed over an unauthenticated HTTP connection. If you are happy for complete health information to always be exposed you can set
endpoints.health.sensitive
tofalse
.
解决方法是在application.properties
中设置endpoints.health.sensitive
为false
。
application.properties
endpoints.health.sensitive=false
对于 >1.5.1 application.properties
management.security.enabled=false
在 Spring Boot 2.0.0.RELEASE(感谢 @rvit34
和 @nisarg-panchal
):
management:
endpoint:
health:
show-details: "ALWAYS"
endpoints:
web:
exposure:
include: "*"
management.endpoints.web.exposure.include=*
公开所有端点,如果你想要的话。
当前文档可在此处找到:https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html
https://stackoverflow.com/questions/32971182/