【问题标题】:Prometheus config doesn't work with Spring boot 2.3.0: ClassNotFoundException: io.micrometer.prometheus.HistogramFlavorPrometheus 配置不适用于 Spring boot 2.3.0:ClassNotFoundException:io.micrometer.prometheus.HistogramFlavor
【发布时间】:2020-09-06 13:02:25
【问题描述】:

应用程序在 2.2.6 版本中正常工作,但随着应用程序升级到最新版本的 spring boot 2.3.0,它停止工作并在启动过程中失败。

2020-05-20T08:43:04.408+01:00 [APP/PROC/WEB/0] [OUT] 2020-05-20 07:43:04.407 ERROR 15 --- [ main] o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'webMvcMetricsFilter' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/web/servlet/WebMvcMetricsAutoConfiguration.class]: Unsatisfied dependency expressed through method 'webMvcMetricsFilter' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'compositeMeterRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/CompositeMeterRegistryConfiguration.class]: Unsatisfied dependency expressed through method 'compositeMeterRegistry' parameter 1; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'prometheusMeterRegistry' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfiguration.class]: Unsatisfied dependency expressed through method 'prometheusMeterRegistry' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'prometheusConfig' defined in class path resource [org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusMetricsExportAutoConfiguration.class]: Unsatisfied dependency expressed through method 'prometheusConfig' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'management.metrics.export.prometheus-org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusProperties': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.springframework.boot.actuate.autoconfigure.metrics.export.prometheus.PrometheusProperties] from ClassLoader [org.springframework.boot.loader.LaunchedURLClassLoader@4f3f5b24]

可以在开始跟踪的底​​部看到下面的类未找到异常。

【问题讨论】:

    标签: prometheus spring-boot-actuator spring-boot-2


    【解决方案1】:

    查看您包含的部分日志文件时,在我看来,多个依赖项并非全部存在或工作正常。请参阅 Spring Boot 使用依赖管理器的建议:https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-build-systems

    升级时,检查版本之间的发行说明/变更日志总是有用的。

    如果您需要更多帮助,请提供有关您的配置的信息;

    1. 您的 pom 文件(或其他依赖管理文件)
    2. 您认为导致问题的“prometheus 配置”

    【讨论】:

      【解决方案2】:

      在您的特定情况下,micrometer-registry-prometheus 必须与 spring boot 的 micrometer-core 版本一致。它是 1.5.1,因为 Spring Boot (Actuator) 在 2.3.0 版本中引入了该依赖项。

        implementation group: 'io.micrometer', name: 'micrometer-registry-prometheus', version: '1.5.1'
      

      【讨论】:

        【解决方案3】:

        添加这个答案,因为我最初不明白

        必须与 spring boot 的 micrometer-core 版本一致。

        lestar cdog 回答

        micrometer-registry-prometheus 包必须与 io.micrometer:micrometer-core 的版本相匹配。 io.micrometer:micrometer-core 由 spring acutuator 依赖拉动。

        您可以在 IDE 中查看 io.micrometer:micrometer-core 的版本

        IntelliJ: 项目窗口(cmd + 1) -> 外部库

        【讨论】:

        • 是的,即使从 Spring Boot 2.3.0 更改为 2.3.4 也需要您将 micrometer-registry-prometheus 从 1.5.1 更新为 1.5.5,否则您会收到此错误...
        猜你喜欢
        • 2020-05-05
        • 1970-01-01
        • 1970-01-01
        • 2016-11-25
        • 1970-01-01
        • 2017-06-27
        • 2021-11-23
        • 2015-04-13
        • 2018-10-18
        相关资源
        最近更新 更多