Workaround for the Grails External Configuration Loading Problem

Grails frees us from writing a lot of  boiler-plate code. But sometimes things come up which don’t go so well as expected. One such thing is related to user provided external configuration files in grails-app/conf directory which come in form of simple properties files.

We have been experiencing a problem with these files — they don’t always get picked up by grails during the first launch of the application. The properties in the files are not read. When you restart the application, the problem goes away. (grails 1.3.5)

As a workaround, we had to hook into the grails event processing infrastructure by putting a simple groovy script named Events.groovy in scripts folder of the project. Grails processes the script after each event. All you have to do is to decide which events are relevant to you. The advantage of this approach is that you don’t touch the grails code.

The workaround boils down to putting some code in the Events.groovy which reacts to the CompileEnd event by copying all you properties files to the directory grailsSettings.resourcesDir.path from grailsSettings.baseDir.path + '/grails-app/conf'.

More can be read here and here.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s