java - Spring Boot - Spring Boot Starter Actuator 的问题
问题描述
所以我正在创建一个新的 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>
启动应用程序时出错:
***************************
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
但有同样的问题。
我不确定我在这里缺少什么,任何帮助将不胜感激。
解决方案
假设您要将 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 上。
推荐阅读
- mysql - 一系列单元格中一组术语的出现次数
- java - Azure 事件中心 Java 客户端未处理数据
- ios - 如何在导航控制器上方添加视图?
- clojure - lein test with-profile 无法覆盖测试配置文件的 env 值
- jquery - jQuery帮助按钮导致调用页面动作
- azure-cognitive-search - 基于搜索列的 Azure 搜索排名
- jquery - 动态 DOM:如何在添加/删除动态元素以及在 DOM 中向上/向下移动元素时增加/减少 ID/名称?
- reactjs - 变量作为插值字符串
- javafx - 将 JavaFX 标签绑定到 StringProperty
- scapy - 如何使用 scapy 实现 stp、rstp、mstp 协议?