views:

2004

answers:

2

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?

+6  A: 

here it is:

import org.codehaus.groovy.grails.commons.ConfigurationHolder
println ConfigurationHolder.config.grails.serverURL

alternatively, in controllers and tags, apparently this will work:

grailsApplication.config.grails.serverURL

I needed it in BootStrap, so option 1 was what I needed.

danb
+10  A: 

danb is on the right track. However, life gets a bit easier on your fingers if you do a nicer import:

import org.codehaus.groovy.grails.commons.ConfigurationHolder as CH
println CH.config.grails.serverURL
Robert Fischer
very nice.. i was completely unaware of that feature, which I will call import aliasing.
danb