Sometimes you will need to switch up configuration in a hurry. For example, you may need to switch the database connection URL in order to use your warm standby database. This can be a pain in Grails because the convient-during-development Config.groovy is compiled both by grails run-app and grails war.
The simplest way to change configuration without rebuilding and redeploying your Grails application is to make use of an externalized configuration file. Although would appear to be very straight forward based on the docs, you will need to jump through a couple undocumented hoops to get it working in all environments.
- Create your override configuration file in the grails-app/conf folder. I called mine override.conf. For now you can leave it empty.
- Enable this external configuration file by pasting this into the top of your grails-app/conf/Config.groovy file:
This is where the docs end. When you start up grails you’ll see the following error message:
- Grails uses different paths in run-app mode and when being run as a war. We’re going to need to add a step post compilation to ensure our configuration file is available at all times. We’ll do this by modifying
Events.groovyif you’ve been migrating your grails app since v1.1). Open
scripts/_Events.groovy, or create it if it does not exist.
- Add the following to _Events.groovy (or merge it in if you already have an
- Try setting a new property and fire up grails as usual. For example, if you want to set the database URL, you’d add this to your grails-app/conf/override.properties file: