在spring-boot集成测试中使用H2数据库的JDBC连接错误

时间:2015-06-15 03:38:36

标签: jdbc spring-boot h2

在我的集成测试中启动服务时,我收到JDBC连接错误 -

WARN 8784 --- [HelperThread-#2] c.m.v2.resourcepool.BasicResourcePool    : com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@57453b70 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception: 

org.h2.jdbc.JdbcSQLException: Connection is broken: "java.net.ConnectException: Connection refused: connect: localhost:59000" [90067-184]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
    at org.h2.message.DbException.get(DbException.java:168)
    at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:450)
    at org.h2.engine.SessionRemote.connectEmbeddedOrServer(SessionRemote.java:327)
    at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:108)
    at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:92)
    at org.h2.Driver.connect(Driver.java:72)
    at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1127)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1114)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44)
    at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1855)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)


    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
    at java.net.Socket.connect(Socket.java:579)
    at org.h2.util.NetUtils.createSocket(NetUtils.java:122)
    at org.h2.util.NetUtils.createSocket(NetUtils.java:102)
    at org.h2.engine.SessionRemote.initTransfer(SessionRemote.java:112)
    at org.h2.engine.SessionRemote.connectServer(SessionRemote.java:446)
    ... 13 common frames omitted

这是应用程序属性文件 -

dataSource.driverClassName=org.h2.Driver
dataSource.url=jdbc:h2:tcp://localhost:59000/./target/servicedatabase-db;MODE=Oracle;IGNORECASE=TRUE;IFEXISTS=TRUE
dataSource.username=sa
dataSource.password=sa
dataSource.maxActive=2
dataSource.initialSize=1
dataSource.maxIdle=1

我无法理解导致问题的原因。任何指针都表示赞赏。

1 个答案:

答案 0 :(得分:0)

在进行maven清洁验证时,测试运行良好,但不是单独进行。当时我们可以讨论这个话题。