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?
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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With