0

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

马文:

<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

如何解决问题?

4

1 回答 1

2

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

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

不符合2.2.5 分支中的调用isJdbc41Compliant()。该代码已在 2.2.5中删除。其次,如果您使用的是 2.2.5 并且您设置了jdbcUrl不需要dataSourceClassName,它们是互斥的。尝试一个干净的构建,作为最后的手段,进入你的 .m2/repositories 目录,找到并删除所有 HikariCP 工件并让它们重新下载。

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

于 2014-11-24T14:50:09.580 回答