无法在Linux服务器上运行Grails应用程序-Tomcat和H2数据库

无法在Linux服务器上运行Grails应用程序-Tomcat和H2数据库,tomcat,grails,deployment,h2,Tomcat,Grails,Deployment,H2,我想在Linux服务器上运行一个带有嵌入式H2数据库、Tomcat和Gradle的Grails应用程序。规格如下 Grails2.4.4 Groovy 2.3.7 梯度2.2.1 Tomcat 7.0.59 Linux CentOS 6 BuildConfig.groovy如下所示 dependencies { test "org.grails:grails-datastore-test-support:1.0.2-grails-2.4" } plugins { build ":

我想在Linux服务器上运行一个带有嵌入式H2数据库、Tomcat和Gradle的Grails应用程序。规格如下

Grails2.4.4 Groovy 2.3.7 梯度2.2.1 Tomcat 7.0.59 Linux CentOS 6 BuildConfig.groovy如下所示

dependencies {
    test "org.grails:grails-datastore-test-support:1.0.2-grails-2.4"
}
plugins {
    build ":tomcat:7.0.55"
    compile ":scaffolding:2.1.2"
    compile ':cache:1.1.8'
    compile ":asset-pipeline:1.9.9"
    runtime ":hibernate4:4.3.6.1"
    runtime ":database-migration:1.4.0"
    runtime ":jquery:1.11.1"
}
下面是detasurece.groovy

dataSource {
    pooled = true
    jmxExport = true
    driverClassName = "org.h2.Driver"
    username = "sa"
    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
    singleSession = true // configure OSIV singleSession mode
    flush.mode = 'manual' // OSIV session flush mode outside of transactional context
}

// environment specific settings
environments {
    development {
        dataSource {
            dbCreate = "create-drop" // one of 'create', 'create-drop', 'update', 'validate', ''
            url = "jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
        }
    }
    test {
        dataSource {
            dbCreate = "update"
            url = "jdbc:h2:mem:testDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
        }
    }
    production {
        dataSource {
            dbCreate = "update"
            url = "jdbc:h2:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
            properties {
               // See http://grails.org/doc/latest/guide/conf.html#dataSource for documentation
               jmxEnabled = true
               initialSize = 5
               maxActive = 50
               minIdle = 5
               maxIdle = 25
               maxWait = 10000
               maxAge = 10 * 60000
               timeBetweenEvictionRunsMillis = 5000
               minEvictableIdleTimeMillis = 60000
               validationQuery = "SELECT 1"
               validationQueryTimeout = 3
               validationInterval = 15000
               testOnBorrow = true
               testWhileIdle = true
               testOnReturn = false
               jdbcInterceptors = "ConnectionState"
               defaultTransactionIsolation = java.sql.Connection.TRANSACTION_READ_COMMITTED
                }
        }
    }
}
通过这个配置,我创建了一个war文件

grails prod war
然后,我在Linux服务器上部署了一个Grails应用程序。雄猫跑得很好。我可以访问。之后,我访问了。结果,它返回了http代码

HTTP Status 404
我检查了/etc/local/tomcat/log/stacktrace.log

[localhost-startStop-1] ERROR StackTrace  - Full Stack Trace:
org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'transactionManagerPostProcessor': 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.h2.jdbc.JdbcSQLException: 
Error opening database: "Could not save properties /prodDb.lock.db" [8000-176]

看起来像是权限问题,它正在尝试在根目录中创建文件

尝试将prod env中的数据源url更改为

 url = jdbc:h2:~/db/test;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"

我使用的另一种方法是将生产数据库放入内存,如下所示(如果不需要将数据库持久化到磁盘上):

url = jdbc:h2:mem:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"

这不依赖于服务器上的任何磁盘权限,例如,在生产环境中,您甚至没有帐户,因此~/不是有效的目录。

我将权限添加到应用程序的所有文件中,但出现了相同的错误。我运行以下命令chmod775-R/usr/local/tomcat/webapps/myAppEven,但我不明白为什么。我认为应该在grails应用程序创建之初对其进行更改。