Since Grails 2.0, the usage of org.codehaus.groovy.grails.commons.ConfigurationHolder
has been deprecated, and you get a very annoying warning, even when it is being used by one of your plugins.
The recommended way of getting your config since then has been using dependency injection to get the grailsApplication
bean into your controllers or services.
I've found a better (more concise and readable) way to get my configuration. I haven't done any serious research yet, but the only difference at first look is that instead of using DI, I'm getting my configuration from a static method in class grails.util.Holders
.
So, here is an example Config.groovy:
// default grails configuration values
app.default.number = 4
// other configurations
And the way of reading that configuration from a service:
import grails.util.Holders
class FooService {
def foo() {
def defaultNumber = Holders.config.app.default.number
assert defaultNumber == 4
}
}
This is very good. I didn't come across this in the grails 2.3.9 documentation. Thanks for throwing it up on gist.