Reputation:
In my Config.groovy I consolidate properties files in the following way:
grails.config.locations << "file:${userHome}/environment.properties" << "file:${userHome}/passwords.properties"
I have two problems:
Can anyone shed light on these issues?
Upvotes: 0
Views: 2072
Reputation: 448
What I do is to have an external Config.groovy file, for instance: MyConfig.groovy
At the end of the standard grails Config.groovy file, I have the following:
def ENV_NAME = "MY_EXTERNAL_CONFIG"
if(!grails.config.locations || !(grails.config.locations instanceof List)) {
grails.config.locations = []
}
if(System.getenv(ENV_NAME)) {
grails.config.locations << "file:" + System.getenv(ENV_NAME)
} else if(System.getProperty(ENV_NAME)) {
grails.config.locations << "file:" + System.getProperty(ENV_NAME)
} else {
println "No external Configs found."
}
So now you can have a MyConfig.groovy file anywhere in production environment (for example) and then set an Environment system variable to point to this file (or pass it as parameter to startup.sh), before you start tomcat:
MY_EXTERNAL_CONFIG="/home/tomcat/configs/MyConfig.groovy"
export MY_EXTERNAL_CONFIG
That's it. Now you have an external MyConfig.groovy file. The properties in it are accessible from your grails app as they were part of the standard Config.groovy
import org.codehaus.groovy.grails.commons.*
//...
ConfigurationHolder.config.foo.bar.hello
Upvotes: 1
Reputation: 12128
how about trying this!(just a guess, it should not make any difference! however give it a shot and let me know if doesnt work!)
grails.config.locations = [ "file:${userHome}/environment.properties",
"file:${userHome}/passwords.properties" ]
Upvotes: 0