如何在Grails中创建自定义环境?
grails.util.Environment定义了一些预配置的环境
>发展 运行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标志一起使用吗? 解决方法
我不这么认为,对于其他地方,你需要使用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 } }
是的,您应该能够声明-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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |