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

后端 未结 4 1079
慢半拍i
慢半拍i 2020-12-13 00:32

in Config.groovy I see this:

// set per-environment serverURL stem for creating absolute links
environments {
    production {
        grails.serverURL = \"h         


        
4条回答
  •  南方客
    南方客 (楼主)
    2020-12-13 00:56

    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?

提交回复
热议问题