>发展
>生产
>测试
>自定义
运行Grails命令时,可以使用-Denv标志来指定要使用的环境. grails run-app -Denv = test.您还可以使用闭包指定特定于特定环境的代码块,例如:
environments { production { grails.serverURL = "http://www.changeme.com" } development { grails.serverURL = "http://localhost:8080/${appName}" } test { grails.serverURL = "http://localhost:8080/${appName}" } }
这些环境特定的关闭可以在Bootstrap.groovy和Config.groovy中使用,还有其他地方吗?
另外,我有可能定义自己的环境,例如PRE_PRODUCTION,以便它可以使用上面的关闭和-Denv标志?
最后,可以将CUSTOM环境与-Denv标志一起使用吗?
解决方法
These environment-specific closures
can be used in Bootstrap.groovy and
Config.groovy,are there other places?
我不这么认为,对于其他地方,你需要使用Generic Per Environment Execution块
Environment.executeForCurrentEnvironment { production { // do something in production } development { // do something only in development } pre_production { // do something for your custom environment } }
Also,is it possible for me to define
my own environment,e.g.
PRE_PRODUCTION,such that it will work
with the closures above and the -Denv
flag?
是的,您应该能够声明-Dgrails.env = pre_production,并在Bootstrap.groovy或Config.groovy(或上述自定义grails.util.Environment块)中包含pre_production块.
编辑
如您在Grails source for Environment中可以看到的那样,这种定制环境将枚举到Environment.CUSTOM,然后在Environment.executeForCurrentEnvironment块中,它将为check against CUSTOM,and the name of the custom environment