gpt4 book ai didi

java - Spring Boot - Spring Boot Starter Actuator 的问题

转载 作者:行者123 更新时间:2023-12-01 17:05:57 25 4
gpt4 key购买 nike

所以我正在创建一个新的 spring boot 项目,并想尝试一下 spring-boot-starter-actuator。但是,我在启动应用程序时遇到了问题。

Pom 片段:

      <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!--<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

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

spring-boot在我的类路径上: enter image description here

启动应用程序时出错:

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

org.springframework.boot.actuate.autoconfigure.metrics.orm.jpa.HibernateMetricsAutoConfiguration.bindEntityManagerFactoryToRegistry(HibernateMetricsAutoConfiguration.java:68)

The following method did not exist:

io.micrometer.core.instrument.binder.jpa.HibernateMetrics.<init>(Lorg/hibernate/SessionFactory;Ljava/lang/String;Ljava/lang/Iterable;)V

The method's class, io.micrometer.core.instrument.binder.jpa.HibernateMetrics, is available from the following locations:

jar:file:/C:/Users/rahul/.m2/repository/io/micrometer/micrometer-core/1.0.2/micrometer-core-1.0.2.jar!/io/micrometer/core/instrument/binder/jpa/HibernateMetrics.class

It was loaded from the following location:

file:/C:/Users/rahul/.m2/repository/io/micrometer/micrometer-core/1.0.2/micrometer-core-1.0.2.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of io.micrometer.core.instrument.binder.jpa.HibernateMetrics

此时出现异常: enter image description here

但是 HibernateMetrics 只有一个构造函数看起来像这样:

public HibernateMetrics(EntityManagerFactory entityManagerFactory, String entityManagerFactoryName, Iterable<Tag> tags) {
this.tags = Tags.concat(tags, "entityManagerFactory", entityManagerFactoryName);
this.stats = hasStatisticsEnabled(entityManagerFactory) ? getStatistics(entityManagerFactory) : null;
}

从依赖分析器中可以看到micrometer-core不存在多个版本。 : enter image description here

我也尝试过 spring-boot-starter-actuator version of 2.2.0.RELEASE但这有同样的问题。

我不确定我在这里缺少什么,任何帮助将非常感激。

最佳答案

假设您将 spring-boot-actuator 应用程序连接到 JMX 控制台。 (“因为它不是网络应用程序”)

我根据您的 pom 依赖项和 CommandLineRunner 示例使用了 Spring Initializr。 Github 示例:https://github.com/thiagochagas/actuator-example

调整:我已经删除了“spring-boot-starter”依赖项:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>

我在 DemoApplication 类中使用了 Thread.sleep(30000L) 来简化示例。

安装并运行应用程序:

./mvnw clean install
java -jar target/demo-0.0.1-SNAPSHOT.jar

打开jconsole:

$JAVA_HOME/bin/jconsole

当您的应用程序运行时,它应该位于 jconsole 上。

选择“demo-0.0.1-SNAPSHOT.jar”进行分析: enter image description here

如果显示此消息,请选择“不安全连接”选项: enter image description here

正在运行的应用程序分析: enter image description here

关于java - Spring Boot - Spring Boot Starter Actuator 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61465712/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com