How do I get at the goodies in my Grails Config.groovy at runtime?

danb picture danb · Oct 13, 2008 · Viewed 28.7k times · Source

in Config.groovy I see this:

// set per-environment serverURL stem for creating absolute links
environments {
    production {
        grails.serverURL = "http://www.changeme.com"
    }
}

what is the correct way to access that at runtime?

Answer

khylo picture khylo · May 15, 2012

In more recent versions of grails ConfigurationHolder has been deprecated.

Instead you should use the grailsApplication object.

grailsApplication.config.grails.serverURL

If in a Controller or Service then use dependency injection of grailsApplication object. e.g.

class MyController{
    def grailsApplication
    def myAction() {
        grailsApplication.config.grails.serverURL
    }

See How to access Grails configuration in Grails 2.0?