启用DropwizardMetrics后运行Vertx代码报ClassNotFoundException错误求助
java.lang.ClassNotFoundException: io.vertx.core.spi.metrics.PoolMetrics in Vert.x Metrics Setup Hey there, I’ve run into this exact issue before when setting up Vert.x with Dropwizard metrics! The problem boils down to missing a critical dependency that provides the metrics SPI implementation your code is trying to use.
What’s causing this?
When you enable DropwizardMetricsOptions in your Vert.x setup, you’re telling Vert.x to use the Dropwizard metrics integration—but your project doesn’t include the actual module that implements those metrics interfaces (like PoolMetrics). Without that module, the JVM can’t find the required class, hence the ClassNotFoundException.
How to fix it
You just need to add the vertx-dropwizard-metrics dependency to your project, matching your Vert.x version. Here’s how to do it for the most common build tools:
Maven (add to your pom.xml)
<dependency> <groupId>io.vertx</groupId> <artifactId>vertx-dropwizard-metrics</artifactId> <version>your-vertx-version</version> <!-- e.g., 4.5.1 --> </dependency>
Gradle
For Groovy DSL (add to build.gradle):
implementation 'io.vertx:vertx-dropwizard-metrics:your-vertx-version'
For Kotlin DSL (add to build.gradle.kts):
implementation("io.vertx:vertx-dropwizard-metrics:your-vertx-version")
Important note
Make sure the version of vertx-dropwizard-metrics matches exactly with the version of Vert.x core you’re using in your project. Version mismatches can lead to other unexpected errors!
Once you add this dependency and rebuild your project, the ClassNotFoundException should disappear, and your metrics setup should work as expected.
内容的提问来源于stack exchange,提问作者eason

