I am using grails 1.2.1 and would like to specify external configuration (properties) files for the war file for my application. I understand from documentation that the proper way to do this is to specify the
grails.config.locations
list in the Config.groovy file. When I do that, however, the properties that should be set are not available to the program (in, for example, DataSource.groovy). When are these properties set?
I would like to load external properties files & then perform some parameter checking on them prior to making them available to the rest of the program. I also want to use these parameter values to set up my logging and data sources.
When the above-mentioned approach didn't work, I also tried loading them manually by doing something like this:
List locations = []
def systemConfig = System.getenv(ENV_NAME)
def cmdlineConfig = System.getProperty(ENV_NAME)
if (systemConfig) {
println "Including configuration file specified in environment: " + systemConfig;
locations << systemConfig
}
if(cmdlineConfig) {
println "Including configuration file specified on command line: " + cmdlineConfig;
locations << cmdlineConfig
}
if (!systemConfig && !cmdlineConfig)
println "WARNING: No external configuration file defined."
locations.each { String loc ->
File f = new File(loc)
if (!f.exists())
println "WARNING: File ${f.absolutePath} not found"
else {
try {
def configSupport = null
if (loc.endsWith('.properties')) {
Properties props = new Properties();
props.load(f.newReader());
println "Parsed properties file: $props"
configSupport = new ConfigSlurper().parse(props)
}
else
configSupport = new ConfigSlurper().parse(f.toURI().toURL() )
assert configSupport != null
println "Loaded ${loc}: $configSupport"
grails.config = grails.config.merge(configSupport)
println "config is now: ${grails.config}"
}
catch( Exception ex ) {
println "ERROR: could not parse $loc: $ex.message"
}
}
}
While grails.config did get set properly, that didn't get reflected to the rest of the code. Also, this is clearly wrong since I need to be able to refer to grails.somepropname rather than to grails.config.grails.somepropname
In short, I am confused about the proper way to inject some properties into my war file and do something with their values.
Thanks,
Gene