Deprecation of ConfigurationHolder in Grails 2

Deprecation of ConfigurationHolder in Grails 2

While porting my Grails applications to 2.0 RC1, I recognized that ConfigurationHolder is now deprecated. The new way to access the configuration is through dependency injection of the grailsApplication bean.

Before 2.0:

import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH
...
def value = CH.config.my.configEntry

With 2.0:

class MyService/MyController {
	def grailsApplication
	def method {
		def value = grailsApplication.config.my.configEntry
	}
}
Grails cheat sheet

Next Article

Grails cheat sheet

A little cheat sheet I created for learning purposes. Feel free to add your hints in the comments.
  1. I’ve been looking into a similar problem and in my investigations found the Holders class written by Burt Beckwith that includes access to config. Details can be found here: http://grails.org/doc/latest/api/grails/util/Holders.html

    Accessing the config then just becomes calling Holders.config which I think is a nicer solution as you can access this from a static context.

    Hope this is useful.