Reusing Grails Variables Inside Config.groovy

In mine Config.groovyI have:

// Lots of other stuff up here...

environments {
    development {
        myapp.port = 7500
    }
    production {
        myapp.port = 7600
    }
}

fizz {
    buzz {
        foo = "Port #${myapp.port}"
    }
}

When I run my application through grails -Dgrails.env=development run-app, my web application rotates without errors, but then at runtime I see that the value fizz.buzz.foois "Port # [:]". I expect it to be "Port No. 7500."

Why does Grails not see my var?

+4
source share
2 answers

Another way is to simply use the variables in your configuration file as follows:

def appPort = 7500

environments {
    production {
        appPort = 7600
        myapp.port = appPort
    }
}

fizz {
    buzz {
        foo = "Port #$appPort"
    }
}

In addition, you do not need to send -Dgrails.environment = development when running the run-app, this is the default.

+1
source

, myapp.port environments, Config.groovy , . myapp.port , fizz.buzz.foo Config.groovy, .

GString, , grails.util.Holders.config, fizz.buzz.foo , :

foo = "Port #${-> Holders.config.myapp.port}"

"Port #${Holders.config.myapp.port}", , Config.groovy.

, , , Spring bean (, spring -security-core bean),

foo = 'Port #${myapp.port}'

, . , ${myapp.port}, Spring, bean.

+3

Source: https://habr.com/ru/post/1538997/


All Articles