网上有很多关于Grails项目数据源的配置的文档,但好多文档将的都是Grails1.X之前的配置,而对于Grails1.X项目数据源的配置绝大多数语焉不详;Grails官方文档也对这个内容一笔带过。
打开网上任何一个有关Grails1数据源配置的文档,都会告诉我们,有关数据源的配置在Grails项目的grails-app/config目录下的DataSource.groovy文件里。
默认的配置为:
dataSource {
pooled = false
driverClassName = "org.hsqldb.jdbcDriver"
username = "sa"
password = ""
}
hibernate {
cache.use_second_level_cache=true
cache.use_query_cache=true
cache.provider_class='org.hibernate.cache.EhCacheProvider'
}
// environment specific settings
environments {
development {
dataSource {
dbCreate = "create-drop" // one of 'create', 'create-drop','update'
url = "jdbc:hsqldb:mem:devDB"
}
}
test {
dataSource {
dbCreate = "update"
url = "jdbc:hsqldb:mem:testDb"
}
}
production {
dataSource {
dbCreate = "update"
url = "jdbc:hsqldb:file:prodDb;shutdown=true"
}
}
}
这个配置能连接Grails项目自带的数据源,这些就不再多说。
我首先在网上查到的对数据源配置的修改如下:
dataSource {
pooled = false
driverClassName = "oracle.jdbc.driver.OracleDriver"
username = "test"
password = "test"
}
hibernate {
cache.use_second_level_cache=true
cache.use_query_cache=true
cache.provider_class='org.hibernate.cache.EhCacheProvider'
dialect = org.hibernate.dialect.Oracle9Dialect
}
// environment specific settings
environments {
development {
dataSource {
url = "jdbc:oracle:thin:@172.16.8.54:1430:test"
}
}
test {
dataSource {
url = "jdbc:oracle:thin:@172.16.8.54:1430:test"
}
}
production {
dataSource {
url = "jdbc:oracle:thin:@172.16.8.54:1430:test"
}
}
}