我想在服务器模式下尝试用户H2数据库来进行grails集成测试,但是存在一个问题:H2GrailsPlugin: Started TCP Server - args: -tcp,-tcpPort,8043
ERROR pool.ConnectionPool - Unable to create initial connections of pool.
Message: Connection is broken: "java.net.ConnectException: Connection refused: localhost:8043"
现在我使用grails h2插件,在我的Config.groovy中使用下一个配置运行H2服务器:
plugins {
h2 {
tcpserver {tcpPort = 8043;}
}
}
这是我的DataSourse:
test {
dataSource_one {
pooled = true
driverClassName = "org.h2.Driver"
username = "sa"
password = ""
dbCreate = "update"
//url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
url = "jdbc:h2:tcp://localhost:8043/testDb"
}
我也尝试在我的Bootstrap.groovy中直接运行服务器:
import grails.util.Environment
import org.h2.tools.Server
class BootStrap {
Server server
def init = { servletContext ->
println "INIT"
if(Environment.current == Environment.TEST){
server = Server.createTcpServer('-tcpPort', '8043').start()
}
}
def destroy = {
server.stop()
}
}
但是此代码未执行,之前引发了异常原因。如果有人帮我解决这个问题,那就太好了。