org.springframework.boot.actuate.autoconfigure.metrics.MetricsEndpointAutoConfiguration 上的错误处理条件

Error processing condition on org.springframework.boot.actuate.autoconfigure.metrics.MetricsEndpointAutoConfiguration

我是一个新手JavaSpring程序员。我正在将一些测试代码从一个旧的 jHipster 项目移到一个新的项目中。我将其添加到 pom.xml 以修复编译错误。这解决了我的编译问题,但导致了运行时错误。

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-actuator</artifactId>
   <version>1.5.7.RELEASE</version>
</dependency>

我现在遇到这些运行时错误。

Caused by: java.lang.IllegalStateException: Error processing condition on org.springframework.boot.actuate.autoconfigure.metrics.MetricsEndpointAutoConfiguration Caused by: java.lang.IllegalArgumentException: Could not find class [org.springframework.boot.actuate.metrics.MetricsEndpoint]

 <spring-boot.version>2.2.5.RELEASE</spring-boot.version>

如果我删除 spring-boot-actuator

incompatible types: java.time.Instant cannot be converted to java.util.Date cannot access org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter method does not override or implement a method from a supertype

有人知道怎么解决吗?

依赖关系似乎有问题。首先,除非您非常确定不会有任何依赖冲突,否则不要指定版本。这是 spring-boot 如此受欢迎的原因之一,您无需担心依赖关系及其兼容性。让 spring-boot 来处理。兼容版本将从父版本继承。

另一个问题是,为什么要使用spring-boot-actuator?你应该使用 spring-boot-starter-actuator

这是一个示例 pom

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.8.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

然后在dependencies

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
    <scope>provided</scope>
    <!-- Spring will find the version compatible with the parent -->
</dependency>

希望对您有所帮助