【问题标题】:Grails War unable to deploy to Tomcat - Error: org.postgresql.Driver not foundGrails War 无法部署到 Tomcat - 错误:找不到 org.postgresql.Driver
【发布时间】:2014-03-21 08:07:47
【问题描述】:

我有一个使用 PostgreSQL 的 grails 应用程序。一切都很好,当我使用 grails 控制台时: grails 运行应用程序 grails 测试应用程序 圣杯清洁 圣杯战争 grails编译

在 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
....

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

【问题讨论】:

  • 如果您的问题得到解答,请接受。

标签: java grails tomcat7 war postgresql-9.3


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    不仅是 Library 和 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"
                }
            }
        }
    }
    

    【讨论】:

    • 当然。这是正确的!因为它在使用 grails 命令时正在运行。但我找到了解决方案,我需要将数据库驱动程序库处理到 web 服务器的 lib 文件夹,例如:tomcat。谢谢
    猜你喜欢
    • 1970-01-01
    • 2023-03-28
    • 2017-07-07
    • 2013-11-24
    • 1970-01-01
    • 1970-01-01
    • 2012-12-05
    • 1970-01-01
    • 2012-08-10
    相关资源
    最近更新 更多