簡體   English   中英

在Tomcat上進行Grails戰爭部署,要求使用hsql驅動程序而不是mysql

[英]Grails war deployment on Tomcat asking for hsql driver instead of mysql

我有一個grails應用程序,正在嘗試將其部署到Tomcat上。 我曾經在hsql上進行開發,並想將mysql用於生產。 但是當我通過奔跑發動戰爭時

grails prod war demo.war 

並將創建的戰爭部署在tomcat / webapps目錄中,出現以下錯誤

INFO: Deploying web application archive demo.war
2011-11-29 17:30:03,193 [Thread-2] INFO  cfg.Environment  - Hibernate 3.3.1.GA
2011-11-29 17:30:03,224 [Thread-2] INFO  cfg.Environment  - hibernate.properties not found
2011-11-29 17:30:03,240 [Thread-2] INFO  cfg.Environment  - Bytecode provider name : javassist
2011-11-29 17:30:03,251 [Thread-2] INFO  cfg.Environment  - using JDK 1.4 java.sql.Timestamp handling
2011-11-29 17:31:25,451 [Thread-2] ERROR context.ContextLoader  - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class 'org.hsqldb.jdbcDriver' for connect URL 'jdbc:mysql://localhost:3306/demoapp?autoreconnect=true'
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

令人費解的是,我已經從Datasource.groovy文件中完全刪除了hsql依賴項。 這是我的Datasource.groovy現在的外觀。

dataSource {
    pooled = true
    driver.name = "com.mysql.jdbc.Driver"   
    username = "root"
    password = "root"
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = true
    cache.provider_class = 'net.sf.ehcache.hibernate.EhCacheProvider'
}
// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop','update'
            pooled = true
            driver.name = "com.mysql.jdbc.Driver"
            url = "jdbc:mysql://localhost/demoapp_dev?autoreconnect=true"
            username = "root"
            password = ""
        }
    }
    test {
        dataSource {
            pooled = true
            driver.name = "com.mysql.jdbc.Driver"
            dbCreate = "update"
            url = "jdbc:mysql://localhost/demoapp_test?autoreconnect=true"
            username = "root"
            password = ""
        }
    }
    production {
        dataSource {
            pooled = true
            driver.name = "com.mysql.jdbc.Driver"
            dbCreate = "update"
            url = "jdbc:mysql://localhost/demoapp?autoreconnect=true"
            username = "root"
            password = ""
        }
    }
}

我該如何解決這個問題? 任何幫助表示贊賞。

嘗試使用driverClassName而不是driver.name來定義您的DataSource驅動程序。

根據schmolly159的回答,當您在類路徑中沒有MySQL驅動程序且沒有driverClassName ,就會發生這種情況。

確保mysql-connector-java-xxxx.jar在您的lib目錄中,或在BuildConfig.groovy中將其聲明為依賴項

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM