我有一个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
如何解决问题?
答案 0 :(得分:2)
一些事情。您的stacktrace中的例外:
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驱动程序。