2014-04-08 28 views
2

在我BuildConfig.groovy的Grails 2.3.7连接到远程PostgreSQL服务器

我:

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:[email protected] 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:[email protected] 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:[email protected] 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

'Grails的清洁'在更改后需要。不知何故,您的旧数据源正在被引用,它指向内存中的h2数据库。 – dmahapatro

回答

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 
} 
+0

是的,你是对的,如果我把运行时'org.postgresql:postgresql:9.3-1100-jdbc4',它的工作原理,我做了一些研究。我们用于连接数据源服务器的postgresql-jdbc jar取决于java版本。 例如: 对于Java 6使用: 的PostgreSQL-9.2-1004-jdbc4.jar 的PostgreSQL-9.3-1100-jdbc4.jar 对于Java 7使用: 的PostgreSQL-9.2-1004-jdbc41.jar 的PostgreSQL -9.3-1100-jdbc41.jar 如果我们没有正确版本的jar。我们会遇到以下问题: – user3511317