我相信我在互联网上阅读了几乎所有的教程,并且阅读了很多这样的答案,但我仍然被卡住了。
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: ALWAYS3.包含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"
}
}
}有什么我可能错过的吗?
发布于 2019-11-28 02:53:15
我找到了解决方案,但不确定是什么原因。这个类确实没有注册为bean,令人惊讶的是,显式添加基本包属性会有所帮助:
@SpringBootApplication(scanBasePackages="com.example.*")有趣的是,在不同的项目中不需要执行上述操作。
发布于 2020-09-16 02:41:16
有趣的是,应用程序容器不识别HealthIndicator的基包,而是将类声明为@component构造型。
修复此问题-在主Spring boot应用程序类中声明HealthIndicator的基包:@SpringBootApplication (scanBasePackages = "basepackage for your class HealthCheck")公共类PaymentServiceApplication {
public static void main(String[] args) {
SpringApplication.run(PaymentServiceApplication.class, args);
}}
编辑:注意-上面声明的基础package="“不是主要的弹簧启动类,这是不必要的。
您必须停止服务器,然后干净地生成maven应用程序,然后重新启动服务器并重新运行应用程序。
现在,您可以运行查找自定义健康端点。
发布于 2022-02-28 03:29:32
我也遇到了问题,我怀念的是
management:
endpoint:
health:
show-details: alwayshttps://stackoverflow.com/questions/59000565
复制相似问题