我想在 grails 中将数据库从 inbuild H2 更改为 Mysql 数据库,Grails 文档说 Datasource.groovy 文件中的更改将更改数据库,但它仅适用于我的开发环境而不适用于测试环境,即使我尝试删除完整的Datasource.groovy 文件并从 mysql 中删除数据库并尝试运行测试它就成功了,所以任何人都可以帮助我做错了什么。
我已经在 stackoverflow 中解决了几乎所有问题,每个人都建议在 DataSource.groovy 文件中进行更改,但它对我不起作用。
dataSource {
pooled = true
driverClassName = "com.mysql.jdbc.Driver"
dialect = "org.hibernate.dialect.MySQL5InnoDBDialect"
username = "root"
logSql =true
password = "root"
properties {
maxActive = -1
minEvictableIdleTimeMillis = 1800000
timeBetweenEvictionRunsMillis = 1800000
numTestsPerEvictionRun = 3
testOnBorrow = true
testWhileIdle = true
connectionProperties = "[autoReconnectForPools=true]"
testOnReturn = true
validationQuery = "SELECT 1"
}
}
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = true
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
environments {
development {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop','update'
url = "jdbc:mysql://127.0.0.1/devenvi"
}
}
test {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop','update'
url = "jdbc:mysql://127.0.0.1/testenvi"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:mysql://127.0.0.1/prodenvi"
}
}
}