grail mongodb - TuPengXiong/TuPengXiong.github.io GitHub Wiki
###Grails引入mongodb
####1.首先在项目的 /grails-app/conf/BuildConfig.groovy文件中加入以下代码,引入插件:
plugins {
compile ':mongodb:3.0.3'//mongodb的版本,这里以3.0.3为例
}
如果我们需要使用mongodb,需要先把plugins的Hibernate的配置先去掉。当然也可以在domain的代码中指定。
####2.然后在项目的 /grails-app/conf/DataSource.groovy文件中加入以下代码,配置mongodb相关信息:
environments { development {
grails {
mongo {
host = "localhost"
databaseName = "dbname"
username = "username"
password = "password"
options {
autoConnectRetry = true//自动重新连接
connectTimeout = 1000 //连接超时时间
}
}
}
}
test {
grails {
mongo {
host = "localhost"
databaseName = "dbname"
username = "username"
password = "password"
}
}
}
production {
grails {
mongo {
host = "localhost"
databaseName = "dbname"
username = "username"
password = "password"
}
}
}
}
###之后就可以实验一下了.