Reputation: 11645
I have setup an environment variable like this:
APP_HOME = "c:\app\app-datasource.properties
in config.groovy I do
def ENV_NAME = "APP_HOME"
if(!grails.config.location || !(grails.config.location instanceof List)) {
grails.config.location = []
}
if(System.getenv(ENV_NAME)) {
println "Including configuration file specified in environment: " + System.getenv(ENV_NAME);
grails.config.location << "file:" + System.getenv(ENV_NAME)
} else if(System.getProperty(ENV_NAME)) {
println "Including configuration file specified on command line: " + System.getProperty(ENV_NAME);
grails.config.location << "file:" + System.getProperty(ENV_NAME)
} else {
println "No external configuration file defined."
}
I got this from a post online, I want to know if we need to use grails.config.location
or grails.config.locations
?
Also instead of APP_HOME
being set to the properties file directly, can I set it to a directory path (e.g.: c:\apps)
and then can I have multiple properties files placed in that directory, then if I do the following multiple times will it work?:
grails.config.locations << "file:" + System.getProperty(ENV_NAME)+ "\app-datasource.properties"
grails.config.locations << "file:" + System.getProperty(ENV_NAME)+ "\app-reporting.properties"
and so on...
Thanks in advance
Upvotes: 0
Views: 3114
Reputation: 1244
You need to modify grails.config.locations
(plural). My (very limited) experience says that the external files are probably not loaded until after Config.groovy
is completed.
You might want to consider looking for he additional configuration file on your classpath; then you can put your extra outside of the Grails project (e.g., in your web server's library) or within the grails-app/conf
directory. I have written the instructions on how to do that here.
Here's a post on how to do it from a plugin: https://stackoverflow.com/a/9789506/1269312
Upvotes: 1