我有一个Spring Java Web应用程序。我正在尝试将Hikaricp 2.2.5用于具有以下配置的连接池。

Maven:

<dependency>
    <groupId>com.zaxxer</groupId>
    <artifactId>HikariCP-java6</artifactId>
    <version>2.2.5</version>
    <scope>compile</scope>
</dependency>


XML:

<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
     <property name="minimumIdle" value="5"/>
     <property name="maximumPoolSize" value="200"/>
     <property name="dataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"/>
     <property name="username" value="root"/>
     <property name="password" value="root"/>
     <property name="connectionTestQuery" value="SELECT 1"/>
     <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/app"/>
     <property name="autoCommit" value="true"/>
     <property name="connectionTimeout" value="30000"/>
     <property name="idleTimeout" value="600000"/>
     <property name="maxLifetime" value="1800000"/>
     <property name="poolName" value="LoginPool"/>
</bean>


我收到以下错误NoSuchMethodError

异常堆栈跟踪:

Caused by: java.lang.NoSuchMethodError: java.sql.Connection.getNetworkTimeout()I
    at com.zaxxer.hikari.util.PoolUtilities.isJdbc41Compliant(PoolUtilities.java:245)
    at com.zaxxer.hikari.pool.HikariPool.addConnection(HikariPool.java:412)
    at com.zaxxer.hikari.pool.HikariPool.fillPool(HikariPool.java:500)
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:159)
    at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:110)
    at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:102)
    at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:76)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2006)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1289)
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory(LocalSessionFactoryBean.java:860)
    at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:779)
    at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1479)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1419)
    ... 109 more


该如何解决?

最佳答案

几件事。您的堆栈跟踪中的异常:

at com.zaxxer.hikari.pool.HikariPool.addConnection(HikariPool.java:412)

does not line up with在2.2.5分支中对isJdbc41Compliant()的调用。 2.2.5中的code was removed。其次,如果您使用的是2.2.5,并且正在设置jdbcUrl,则不需要dataSourceClassName,它们是互斥的。尝试进行一个干净的构建,并在最后一个方法进入.m2 / repositories目录,找到并删除所有HikariCP工件,然后重新下载它们。

更新:最后,请确保尽可能使用最新的MySQL驱动程序。

10-08 01:57