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

Cannot run a Grails Application on the Linux Server - Tomcat and H2 database

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

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"
}

下面是Detasourece.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 应用程序。 Tomcat运行好吧。我可以访问 http://myserver:8080. After that, I accessed http://myserver:8080/application/。结果,它返回了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]

似乎是权限问题,正在尝试在根目录中创建文件。

尝试将产品环境中的数据源 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"

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