我想在带有嵌入式 H2 数据库、Tomcat 和 Gradle 的 Linux 服务器上运行 Grails 应用程序。规范如下
- Grails 2.4.4
- 常规 2.3.7
- Gradle 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"
}
下面是 Detasource.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 .之后,我访问了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]
最佳答案
看起来像权限问题,它正在尝试在根目录中创建文件。
尝试将 prod env 中的数据源 url 更改为
url = jdbc:h2:~/db/test;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
关于tomcat - 无法在 Linux 服务器上运行 Grails 应用程序 - Tomcat 和 H2 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29541476/