0

我有一个使用 PostgreSQL 的 grails 应用程序。一切正常,当我使用 grails 控制台时: grails run-app grails test-app grails clean grails war grails compile

在 BuildConfig 中,我有:

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

但是当我尝试打包 .war 文件时,将该文件复制到部署 Tomcat 应用程序的 $CATALINA_HOME/webapps/ 中,然后通过以下方式启动 Tomcat 服务器:catalina.sh start。我在 tracktrace.log 中收到错误消息:

21-Mar-2014 14:45:57.701 SEVERE [localhost-startStop-1] org.apache.tomcat.jdbc.pool.ConnectionPool.init Unable to create initial connections of pool.
java.sql.SQLException: org.postgresql.Driver
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:253)
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:181)
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:699)
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:633)
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:484)
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:142)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:115)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:102)
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:126)

我尝试在 /META-INF/lib 中列出文件/文件夹,我看到:

....
postgresql-9.3-1100-jdbc41.jar
....

我不知道这是怎么回事。有没有人可以帮助我?

4

2 回答 2

1

将 JDBC 驱动程序 JAR 移动到 Tomcat 的 /lib 目录。

于 2014-03-21T08:20:59.873 回答
0

不仅库和 Jar 文件确保您的数据源设置正确,如下所示:

dependencies {
        runtime "postgresql:postgresql:9.1-901.jdbc4"
    }

dataSource {
    pooled = true
    driverClassName = "org.postgresql.Driver"
    dialect = "org.hibernate.dialect.PostgreSQLDialect"
    username = "iqbal"
    password = ""
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory' // Hibernate 3
//    cache.region.factory_class = 'org.hibernate.cache.ehcache.EhCacheRegionFactory' // Hibernate 4
}

// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:postgresql://localhost:5432/seram"
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:postgresql://localhost:5432/seram"
        }
    }
    production {
        dataSource {
            dbCreate = "update"
            url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
            properties {
                maxActive = -1
                minEvictableIdleTimeMillis=1800000
                timeBetweenEvictionRunsMillis=1800000
                numTestsPerEvictionRun=3
                testOnBorrow=true
                testWhileIdle=true
                testOnReturn=false
                validationQuery="SELECT 1"
                jdbcInterceptors="ConnectionState"
            }
        }
    }
}
于 2014-03-21T10:59:43.693 回答