1

我正在尝试将我的 Grails 2.2.4 应用程序部署到 Tomcat 6.5。该应用程序在 DataSource.groovy 中配置了两个环境。

无论我是使用“mvn clean package”还是通过“grails war”构建我的应用程序,我都会收到有关特定表不存在的错误。当我通过“groovy run-app”启动应用程序时,连接到同一个数据库没有问题。知道我的配置有什么问题吗?

Tomcat 部署错误

Nov 12, 2013 4:16:38 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.codehaus.groovy.grails.web.context.GrailsContextLoaderListener
org.springframework.beans.factory.access.BootstrapException: Error executing bootstraps; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; SQL [select count(*) as y0_ from monkey_classification this_]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
        at org.codehaus.groovy.grails.web.context.GrailsContextLoader.initWebApplicationContext(GrailsContextLoader.java:124)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797)
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
        at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
        at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
        at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
        at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:977)
        at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1655)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
        at java.util.concurrent.FutureTask.run(FutureTask.java:166)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
        at java.lang.Thread.run(Thread.java:636)
Caused by: org.springframework.dao.InvalidDataAccessResourceUsageException: could not execute query; SQL [select count(*) as y0_ from monkey_classification this_]; nested exception is org.hibernate.exception.SQLGrammarException: could not execute query
        at BootStrap$_closure4.doCall(BootStrap.groovy:24)
        at grails.util.Environment.evaluateEnvironmentSpecificBlock(Environment.java:308)
        at grails.util.Environment.executeForEnvironment(Environment.java:301)
        at grails.util.Environment.executeForCurrentEnvironment(Environment.java:277)
        ... 6 more
Caused by: org.hibernate.exception.SQLGrammarException: could not execute query
        ... 10 more
Caused by: org.h2.jdbc.JdbcSQLException: Table "MONKEY_CLASSIFICATION" not found; SQL statement:
select count(*) as y0_ from monkey_classification this_ [42102-164]
        at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
        at org.h2.message.DbException.get(DbException.java:169)
        at org.h2.message.DbException.get(DbException.java:146)
        at org.h2.command.Parser.readTableOrView(Parser.java:4753)
        at org.h2.command.Parser.readTableFilter(Parser.java:1080)
        at org.h2.command.Parser.parseSelectSimpleFromPart(Parser.java:1686)
        at org.h2.command.Parser.parseSelectSimple(Parser.java:1793)
        at org.h2.command.Parser.parseSelectSub(Parser.java:1680)
        at org.h2.command.Parser.parseSelectUnion(Parser.java:1523)
        at org.h2.command.Parser.parseSelect(Parser.java:1511)
        at org.h2.command.Parser.parsePrepared(Parser.java:405)
        at org.h2.command.Parser.parse(Parser.java:279)
        at org.h2.command.Parser.parse(Parser.java:251)
        at org.h2.command.Parser.prepareCommand(Parser.java:217)
        at org.h2.engine.Session.prepareLocal(Session.java:415)
        at org.h2.engine.Session.prepareCommand(Session.java:364)
        at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1121)
        at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:71)
        at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:267)
        at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:281)
        at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:313)
        ... 10 more
Nov 12, 2013 4:16:38 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Nov 12, 2013 4:16:38 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/application-monkey-tool-0.1] startup failed due to previous errors
Nov 12, 2013 4:16:38 PM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
Nov 12, 2013 4:16:38 PM org.apache.catalina.loader.WebappClassLoader clearReferencesJdbc
SEVERE: The web application [/application-monkey-tool-0.1] registered the JDBC driver [org.h2.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Nov 12, 2013 4:16:38 PM org.apache.catalina.loader.WebappClassLoader clearReferencesThreads
SEVERE: The web application [/application-monkey-tool-0.1] appears to have started a thread named [net.sf.ehcache.CacheManager@1b4a4fd2] but has failed to stop it. This is very likely to create a memory leak.

数据源.groovy:

dataSource {
    pooled = true
}
hibernate {
    cache.use_second_level_cache = true
    cache.use_query_cache = false
    cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
// environment specific settings
environments {
    development {
        dataSource {
            driverClassName = "com.mysql.jdbc.Driver"
            username = "amt"
            password = "password"
            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:mysql://10.x.x.x:3306/amt"
        }
    }
    test {
        dataSource {
            driverClassName = "org.h2.Driver"
            username = "sa"
            password = ""
            dbCreate = "update"
            url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000"
        }
    }
    production {
        dataSource {
            dataSource {
                driverClassName = "com.mysql.jdbc.Driver"
                username = "amt"
                password = "password"
                dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
                url = "jdbc:mysql://10.x.x.x:3306/amt"
            }
        }
    }
}

Maven构建输出

[INFO] --- grails-maven-plugin:2.2.4:maven-grails-app-war (default-maven-grails-app-war) @ application-monkey-tool ---

|Loading Grails 2.2.4
|Configuring classpath
|Running pre-compiled script
.
|Environment set to prod
.................................
|Packaging Grails application
..
|Compiling 1 source files
..............
|Compiling 21 GSP files for package [applicationMonkeytOol]
..
|Compiling 8 GSP files for package [jodaTime]
.
|Compiling 7 GSP files for package [easygrid]
.
|Compiling 4 GSP files for package [databaseMigration]
..
|Building WAR file
..............................................................
|Done creating WAR target\application-monkey-tool-0.1.war
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 52.528s
[INFO] Finished at: Tue Nov 12 11:12:57 EST 2013
[INFO] Final Memory: 10M/244M
[INFO] ------------------------------------------------------------------------
4

1 回答 1

3

看起来您在 dsl 中定义了两个数据源,应该是这样的:

production {
        dataSource {
                driverClassName = "com.mysql.jdbc.Driver"
                username = "amt"
                password = "password"
                dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
                url = "jdbc:mysql://10.x.x.x:3306/amt"
        }
    }
于 2013-11-12T18:11:12.263 回答