How to get Grails application name within Config.groovy?

眉间皱痕 提交于 2019-12-20 10:39:40

问题


I want to include the Grails application name in some of my configuration settings in grails-app/Config.groovy. I've tried many ways without success. For example, if I have the following in my Config.groovy,

edu.appname1 = "${grailsApplication.metadata.'app.name'}"
edu.appname2 = "${application.metadata.'app.name'}"
edu.appname3 = "${metadata.'app.name'}"
edu.appname4 = "${app.name}"

I can run these statements in the Grails console

def edu = grailsApplication.config.edu
println "${'''${grailsApplication.metadata.'app.name'} -> '''}${edu.appname1}"
println "${'''${application.metadata.'app.name'}       -> '''}${edu.appname2}"
println "${'''${metadata.'app.name'}                   -> '''}${edu.appname3}"
println "${'''${app.name}                              -> '''}${edu.appname4}"

with the following results.

${grailsApplication.metadata.'app.name'} -> [:]
${application.metadata.'app.name'}       -> [:]
${metadata.'app.name'}                   -> [:]
${app.name}                              -> [:]

There must be some way to get this information.


回答1:


To get the appName in a config file that you're including with grails.config.locations you can use:

appName = grails.util.Metadata.current.'app.name'



回答2:


try this:

edu.appname1 = appName

or if you want to use as part of a longer configuration parameter

edu.appname1 = "something.$appName.else"


来源:https://stackoverflow.com/questions/9809566/how-to-get-grails-application-name-within-config-groovy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!