java - Spring Boot 自定义运行状况指示器未显示

标签 java spring spring-boot spring-boot-actuator

我相信遵循了互联网上几乎所有的教程并阅读了许多 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/

相关文章:

java - 通过命令行参数设置 Spring Boot 属性

java - java中的方法无法应用于给定类型错误

java - 使用 JRE 1.5 和 JDK 1.6 时 DocumentBuilder.parse 的区别

java - 哪个Ibatis版本与Spring 4.1.9.RELEASE兼容

java - Spring 注释 @Entry.base 不支持 SpEL

java - Hibernate中查询继承实体时`Unknown column ' Camera ' in ' where子句`

java - Spring Boot 应用程序无法使用 JspTagLib 和 Freemarker 找到 security.tld

java - tomcat 8部署后启动web服务失败

java - 用Java将BsonDocument写入文件

java - 所有时间戳日期减少 2 小时,Java 1.7 和 MS SQL Server