Home > OS >  NoSuchMethodError: com.zaxxer.hikari.HikariDataSource.getMetricsTrackerFactory()Lcom/zaxxer/hikari/m
NoSuchMethodError: com.zaxxer.hikari.HikariDataSource.getMetricsTrackerFactory()Lcom/zaxxer/hikari/m

Time:11-25

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.

CodePudding user response:

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

CodePudding user response:

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>
  • Related