因此,我正在创建一个新的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-boots:

启动应用程序时出错:
***************************
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此时会发生异常:

但是,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:

我也尝试过spring-boot-starter-actuator version of 2.2.0.RELEASE,但也有同样的问题。
我不确定我在这里错过了什么,任何帮助都会非常感谢。
发布于 2020-04-29 02:51:04
假设您要将spring-boot-actuator应用程序连接到JMX控制台。(“因为它不是web应用程序”)
我根据您的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“:

如果显示此消息,请选择选项"Insecure Connection":

正在运行的应用程序的分析:

https://stackoverflow.com/questions/61465712
复制相似问题