我相信遵循了互联网上几乎所有的教程并阅读了许多 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"
}
}
}
有什么我可能错过的吗?
最佳答案
我找到了解决方案,但不确定原因。该类确实没有注册为 bean,令人惊讶的是,显式添加基本包属性有助于:
@SpringBootApplication(scanBasePackages="com.example.*")
有趣的是,不需要在不同的项目中执行上述操作。
关于java - Spring Boot 自定义运行状况指示器未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59000565/