简体   繁体   中英

NoSuchMethodError: com.zaxxer.hikari.HikariDataSource.getMetricsTrackerFactory()Lcom/zaxxer/hikari/metrics/MetricsTrackerFactory

I'm migrating a Java Spring application to Spring Boot. I've transferred the application-context.xml configuration inside Java beans. However, when I try to launch the Spring Boot app, I get the following error:

java.lang.NoSuchMethodError: com.zaxxer.hikari.HikariDataSource.getMetricsTrackerFactory()Lcom/zaxxer/hikari/metrics/MetricsTrackerFactory;

It seems like there is something wrong with my configuration or the library version I'm using, but so far I've no clue. I'm using Spring Boot 2.5.6 and HikariCP 2.5.1.

Here is my data source configuration:

@Primary
@Bean(destroyMethod = "close")
DataSource dataSource(DatasourceProperties datasourceProperties) {
     return DataSourceBuilder.create()
          .type(HikariDataSource.class)
          .driverClassName(datasourceProperties.getDriverClassName())
          .url(datasourceProperties.getUrl())
          .username(datasourceProperties.getUsername())
          .password(datasourceProperties.getPassword())
          .build();
}

I can provide more configuration and info if needed.

As listed in its reference documentation , Spring Boot 2.5.6 requires Hikari 4.0.3. You should upgrade Hikari.

It was a version issue of HikariCP. I noticed HikariDataSource came from com.zaxxer.HikariCP-java7.2.4.13, which was brought by a Quartz dependency.

I excluded this HikariCP library version from Quartz explicitly

<dependency>
  <groupId>org.quartz-scheduler</groupId>
  <artifactId>quartz</artifactId>
  <version>${quartz.version}</version>
  <exclusions>
    <exclusion>
      <groupId>com.zaxxer</groupId>
      <artifactId>HikariCP-java7</artifactId>
    </exclusion>
  </exclusions>
</dependency>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM