mysql - Tomcat 上的 Grails war 部署要求 hsql 驱动程序而不是 mysql

标签 mysql tomcat grails deployment hsqldb

我有一个 grails 应用程序,我正试图将其部署到 Tomcat 上。以前在hsql上开发,想生产用mysql。但是当我通过运行来建立 war 时

grails prod war demo.war 

将创建的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 驱动程序。

关于mysql - Tomcat 上的 Grails war 部署要求 hsql 驱动程序而不是 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8315207/

相关文章:

grails - Groovy:参数链接标签

java - 如何使用 Java servlet 在给定条件下将值插入表中?

mysql - VB.net : Can't connect to mysql (mariadb) with ssl enabled

php - 我如何使用php计算特定字段的多行mysql

java - 碧 Jade 听众?从 Tomcat 8 升级到 Tomcat 9

Tomcat 6 和在部署时更新 context.xml

mysql - `Exists` 和 `IN` 在 MySQL 中给出两个不同的结果

java - "Java HotSpot(TM) 64-Bit Server VM warning: Failed to reserve shared memory. (errno=12)"

jquery - 在groovy gsp中,日期格式不起作用

grails - Grails标记中的默认 body 行为