Reputation: 1176
I've catched java.sql.SQLTransientConnectionException: springHikariCP - Connection is not available, request timed out after 30001ms.
First code block works well, second (CP) does not work.
What is wrong and how fix this?
JDK - 1.8.0_73.
HikariCP - 2.4.5.
Spring - 4.2.5.RELEASE.
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${connection.driverClassName}"/>
<property name="username" value="${connection.userName}"/>
<property name="password" value="${connection.password}"/>
<property name="url" value="${connection.url}"/>
</bean>
CP
<bean id="hikariConfiguration" class="com.zaxxer.hikari.HikariConfig">
<property name="poolName" value="springHikariCP"/>
<property name="dataSourceClassName" value="${connection.dataSourceClassName}"/>
<property name="maximumPoolSize" value="${connection.pool.maximumPoolSize}"/>
<property name="idleTimeout" value="${connection.pool.idleTimeout}"/>
<property name="dataSourceProperties">
<props>
<prop key="url">${connection.url}</prop>
<prop key="user">${connection.userName}</prop>
<prop key="password">${connection.password}</prop>
</props>
</property>
</bean>
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy- method="close">
<constructor-arg ref="hikariConfiguration"/>
</bean>
//...............
#CONNECTION
connection.dataSourceClassName=org.hsqldb.jdbc.JDBCDataSource
connection.url=jdbc:hsqldb:mem:dbtest-local
connection.userName=sa
connection.password=
#POOL
connection.pool.maximumPoolSize=1
connection.pool.idleTimeout=28500
#HIBERNATE
hibernate.hbm2ddl.auto=create-drop
hibernate.dialect=H2Dialect
hibernate.show_sql=true
Upvotes: 3
Views: 10785
Reputation: 242
If you use the dataSourceClassName, you should not provide the jdbc url.
Instead, you should add the host, dbname, etc. as properties. See the example on github:
dataSourceClassName=org.postgresql.ds.PGSimpleDataSource
dataSource.user=test
dataSource.password=test
dataSource.databaseName=mydb
dataSource.portNumber=5432
dataSource.serverName=localhost
Otherwise, you should not use the dataSourceClassName. Try with:
<bean id="hikariConfiguration" class="com.zaxxer.hikari.HikariConfig">
<property name="poolName" value="springHikariCP" />
<property name="maximumPoolSize" value="${connection.pool.maximumPoolSize}" />
<property name="idleTimeout" value="${connection.pool.idleTimeout}" />
<property name="jdbcUrl" value="${connection.url}" />
<property name="dataSourceProperties">
<props>
<prop key="user">${connection.userName}</prop>
<prop key="password">${connection.password}</prop>
</props>
</property>
</bean>
This is working for me in local.
Upvotes: 1