我想在嵌入式H2数据库,Tomcat和Gradle的Linux服务器上运行Grails应用程序。规格低于
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。之后,我访问了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]
答案 0 :(得分:0)
看起来是权限问题,它正在尝试在根目录中创建文件。
尝试将prod env中的数据源URL更改为
url = jdbc:h2:~/db/test;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
答案 1 :(得分:0)
我过去常常使用它的另一种方法 - 如果你不需要将数据库保留在磁盘上 - 就是将生产数据库放入这样的内存:
url = jdbc:h2:mem:prodDb;MVCC=TRUE;LOCK_TIMEOUT=10000;DB_CLOSE_ON_EXIT=FALSE"
这不取决于服务器上的任何磁盘权限(例如,您甚至没有帐户的生产环境,因此“〜/”不是有效目录。)