grails 2.3.7连接到远程postgresql服务器

时间:2014-04-08 14:17:19

标签: postgresql grails jdbc-pool

在我的BuildConfig.groovy

我有:

    dependencies {         
runtime 'org.postgresql:postgresql:9.3-1100-jdbc41'
}

在我的DataSource.groovy

我有:

dataSource {

pooled = true
driverClassName = "org.postgresql.Driver"
dialect=org.hibernate.dialect.PostgreSQLDialect

hibernate {
    cache.use_second_level_cache=true
    cache.use_query_cache=true
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'

}
// environment specific settings
environments {
development {
dataSource {

            dbCreate = "create-drop" // one of 'create', 'create-drop','update'
            url = "jdbc:postgresql://ip:5432/security_dev"
            username = "uname"
            password = "pwd"
        }
    }
    test {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop','update'
            url = "jdbc:postgresql://ip:5432/security_dev"
            username = "uname"
            password = "pwd"

        }
    }
    production {
        dataSource {
            dbCreate = "update" // one of 'create', 'create-drop','update'
            url = "jdbc:postgresql://ip:5432/security_dev"
            username = "uname"
            password = "pwd"
        }

    }
}
}

以下是错误消息

2014-04-08 15:02:48,390 [localhost-startStop-1] ERROR pool.ConnectionPool  - Unable to create initial connections of pool.
Message: Driver:org.postgresql.Driver@afd862b returned null for URL:jdbc:h2:mem:grailsDB;MVCC=TRUE;LOCK_TIMEOUT=10000
    Line | Method
->>  262 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run       in java.lang.Thread
Error |
2014-04-08 15:02:48,708 [localhost-startStop-1] ERROR pool.ConnectionPool  - Unable to create initial connections of pool.
Message: Driver:org.postgresql.Driver@30535975 returned null for URL:jdbc:h2:mem:grailsDB;MVCC=TRUE;LOCK_TIMEOUT=10000
    Line | Method
->>  262 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run       in java.lang.Thread
Error |
2014-04-08 15:02:48,723 [localhost-startStop-1] ERROR pool.ConnectionPool  - Unable to create initial connections of pool.
Message: Driver:org.postgresql.Driver@563105a6 returned null for URL:jdbc:h2:mem:grailsDB;MVCC=TRUE;LOCK_TIMEOUT=10000
    Line | Method
->>  262 | run       in java.util.concurrent.FutureTask
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run . . . in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run       in java.lang.Thread
|Server running. Browse to http://localhost:8080/Postgresql_Grails_2.3.7

此配置适用于Grails 2.2.4

我必须做些什么才能让它在grails 2.3.7下工作?

提前致谢

1 个答案:

答案 0 :(得分:1)

升级后我遇到了同样的问题。这是我的依赖项(jdbc4而不是jdbc41):

dependencies {
    runtime 'org.postgresql:postgresql:9.3-1100-jdbc4'
}

我不知道这是不是问题,但我认为你在休眠之前就离开了'}':

dataSource {
    pooled = true
    driverClassName = "org.postgresql.Driver"
    username = "username"
    password = "password"
}

hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
    singleSession = true 
}