在 Config.groovy 中重用 Grails 变量 [英] Reusing Grails variables inside Config.groovy

查看:18
本文介绍了在 Config.groovy 中重用 Grails 变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 Config.groovy 中,我有:

// Lots of other stuff up here...

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

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

当我通过 grails -Dgrails.env=development run-app 运行我的应用程序时,我的 Web 应用程序启动时没有错误,但是在运行时我看到 fizz.buzz.foo端口号[:]".我希望它是端口#7500".

When I run my app via grails -Dgrails.env=development run-app, my web app spins up without errors, but then at runtime I see that the value of fizz.buzz.foo is "Port #[:]". I would expect it to be "Port #7500".

为什么 Grails 看不到我的 var?

Why isn't Grails seeing my var?

推荐答案

另一种方法是简单地在配置文件中使用变量,如下所示:

Another way is to simply use variables within your config file like this:

def appPort = 7500

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

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

而且,当您执行 run-app 时,您不需要发送 -Dgrails.environment=development,它是默认的.

And also, you don't need to send the -Dgrails.environment=development when you execute the run-app, it's the default one.

这篇关于在 Config.groovy 中重用 Grails 变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆