Spring boot 无法实现弹簧启动执行器自定义健康指示器
我试着按照文档进行操作,但每次检查时都只能看到“状态:向上”。我甚至还返回了Health.down.build(),但我仍然只看到“status:UP”。我不确定我做错了什么。我没有错误。如果您向类中添加Spring boot 无法实现弹簧启动执行器自定义健康指示器,spring-boot,health-monitoring,spring-boot-actuator,Spring Boot,Health Monitoring,Spring Boot Actuator,我试着按照文档进行操作,但每次检查时都只能看到“状态:向上”。我甚至还返回了Health.down.build(),但我仍然只看到“status:UP”。我不确定我做错了什么。我没有错误。如果您向类中添加@组件注释,您的自定义健康指示器将在运行中注册。 如果您随后调用方法actuator/health,我猜您将获得汇总状态: {"status":"DOWN"} 只需将其添加到application.properties即可查看healthdindicator结果的详细视图: managemen
@组件
注释,您的自定义健康指示器
将在运行中注册。
如果您随后调用方法actuator/health,我猜您将获得汇总状态:
{"status":"DOWN"}
只需将其添加到application.properties即可查看healthdindicator
结果的详细视图:
management.endpoint.health.show-details=always
你会得到这样的结果:
{
"status": "DOWN",
"details": {
"MyCustomHealthCheck": {
"status": "DOWN",
"details": {
"remote.system.down": "There is something wrong with system XXX"
}
},
"diskSpace": {
"status": "UP",
"details": {
"total": 499963174912,
"free": 434322321408,
"threshold": 10485760
}
}
}
}您是否已检查是否正在调用您的自定义
HealthIndicator
?你是怎么加的?也许你可以分享一些代码来展示你到目前为止所做的尝试?只需调用:“MyCustomHealthIndicator MyCustomHealthIndicator=new MyCustomHealthIndicator();MyCustomHealthIndicator.health();”我需要创建自己的健康对象吗?你的HealthIndicator
需要是一个bean。它是一个bean吗?My health()方法已经有\@Override注释(如文档中的示例所示),那么,你是说我必须添加\@Bean注释,还是我必须自己在xml文件中将其定义为Bean?它必须是一个Bean,这样你要么需要从@Configuration
类中的@Bean
方法返回它的实例,要么需要用@Component
对该类进行注释。后者就是一个例子