加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

如何在Grails中创建自定义环境?

发布时间:2020-12-14 16:31:40 所属栏目:大数据 来源:网络整理
导读:grails.util.Environment定义了一些预配置的环境 发展 生产 测试 自定义 运行Grails命令时,可以使用-Denv标志来指定要使用的环境. grails run-app -Denv = test.您还可以使用闭包指定特定于特定环境的代码块,例如: environments { production { grails.serv
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标志一起使用吗?

解决方法

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读