Share

August 10, 2010

Grails: External Database Configuration

Grails: 1.3.3

So I been looking for a way to do external configuration and I found this great blog... check it out, I took his code and only use parts of it, but is a great code to get the brain working.

Getting Grails external configuration working in the real world. | BASE Logic, Inc.

here is what i have:

In Config.groovy
def CONFIG_FILE_NAME = "${appName}-config.groovy";

if (!grails.config.locations || !(grails.config.locations instanceof List)) {
  grails.config.locations = []
}
println "--------------------------------------------------------"
// 1: If this is a developer machine, then they will have their own config and I should use that.
if (new File("${userHome}/.grails/${CONFIG_FILE_NAME}").exists()) {
  println "*** User defined config: file:${userHome}/.grails/${CONFIG_FILE_NAME}. ***"
  grails.config.locations = ["file:${userHome}/.grails/${CONFIG_FILE_NAME}"]
}
// 2: Most QA and PROD machines should config should be on the classpath
else {
  grails.config.locations = ["classpath:${CONFIG_FILE_NAME}"]
}

in then the "${appName}-config.groovy" file looks like
dataSource.url="jdbc:mysql://server/dbname"
dataSource.password="password"