【发布时间】:2023-03-27 00:42:01
【问题描述】:
我相信几乎遵循了互联网上的所有教程并阅读了许多 SO 答案,但我仍然被卡住了。
1。一个简单的健康检查
@Component
public class HealthCheck implements HealthIndicator {
@Override
public Health health() {
return Health.up().build();
}
}
2。 Application.yaml 配置为显示所有详细信息:
management.endpoints.web.exposure.include: "*"
management.endpoint.health.show-details: ALWAYS
3。 Spring-boot-actuator 包含为依赖项:
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
4。最新版本的 Spring Boot:
id 'org.springframework.boot' version '2.2.0.RELEASE'
5。主应用程序类使用 @SpringBootApplication 注释(隐含带 @ComponentScan)。
@SpringBootApplication
public class PaymentServiceApplication {
public static void main(String[] args) {
SpringApplication.run(PaymentServiceApplication.class, args);
}
}
我的自定义运行状况检查必须针对 Apache Kafka 进行测试,但为简洁起见,我跳过了详细信息。
尽管如此,调用/actuator/health 端点我得到相同的默认结果:
{
"status": "UP",
"components": {
"diskSpace": {
"status": "UP",
"details": {
"total": 250685575168,
"free": 99168997376,
"threshold": 10485760
}
},
"ping": {
"status": "UP"
}
}
}
有什么我可能错过的吗?
【问题讨论】:
-
我试过了,使用了健康端点。你能做一个system.out吗?在那里再试一次......如果控制台中有东西。
-
验证组件是否实际配置为spring bean。如果没有组件扫描,仅仅注释为@Component 并不能保证它成为一个bean。
-
@Compass,我已经更新了这个问题。主类标注
@SpringBootApplication,开启组件扫描。 -
您的 HealthIndicator 类没有添加任何额外信息。
标签: java spring spring-boot spring-boot-actuator