the following seems to work to externalize datasource configuartion (see http://jira.codehaus.org/browse/GRAILS-3226?page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel)
Basically
1) you add the grails.config.locations property in the Config.groovy like below
grails.config.locations = [ //”classpath:${appName}-config.properties”,
//”classpath:${appName}-config.groovy”,
“file:${userHome}/${appName}-config.properties”]
Notice: I have added the file is users file system , so the user can change it, without touching the war file . Restarting the app should pick up the new value
2) in the ${appName}-config.properties” file
dataSource.driverClassName = com.mysql.jdbc.Driver
dataSource.url=jdbc:mysql://localhost/something
dataSource.username=root
dataSource.password=secret
Notice no quotes in the value
I am using grails 1.2.1
Tags: datasource, Externalized, Grails
October 24, 2012 at 9:00 pm |
Have you successfully used the ‘classpath:{filename.properties}’ method for defining the configuration file? I like the modular style of having environment specific configuration files outside of Config.groovy, but don’t want to have to worry about files outside of the WAR once deployed. I’ve tried it and put my *.properties files in ‘grails-app/conf’, but it always returns an error regarding not being able to find the file specified in Config.groovy. If it helps, this is what I included in Config.groovy:
environments {
development {
grails.config.locations << "classpath:dev-config.properties"
}
prod {
grails.config.locations << "classpath:prod-config.properties"
}
etc….
}
I've also tried specifying "classpath:grails-app/conf/{env}-config.properties" with no luck either. I guess my queston is once you use the classpath option is there a specific location in the grails project that these config files should be put?
October 25, 2012 at 12:45 am |
Looks like a chicken and egg problem
see
http://grails.1312388.n4.nabble.com/using-an-external-property-w-in-Config-groovy-tp3095970p3096041.html
You probably thought of the following and trying to avoid it — but just in case
http://stackoverflow.com/questions/11469276/can-i-split-config-groovy-file-of-grails
“It might not be in the classpath yet, there’s a bug where the properties file won’t be accessible after a clean but will work on the next run-app. But if that’s happening you’d see a warning on the console saying it couldn’t load the file.
But you’re also affected by timing. You specify the external files in Config.groovy but they’re resolved after Config.groovy is parsed, so you can’t use the values inside the file. If you run ‘grails console’ and execute ‘println grailsApplication.config.test.name’ it should print the correct value.”