【问题标题】:What is the corresponding artifact for Config.groovy of grails 2.x in grails 3.x?grails 3.x中grails 2.x的Config.groovy对应的神器是什么?
【发布时间】:2018-12-29 19:31:26
【问题描述】:

我想将应用程序从 grails 2.4.4 迁移到 grails 3.3.9。 由于 grails 2.x 中 conf 目录的结构与 3.x 完全不同,因此 3.x 中不再有 config.groovy。在 2.x 的 config.groovy 中,我曾经为我的选择框定义常量列表,例如:

  metals=['au','ag','pl']    

我通过

访问了它们
static List getMetals() {
    grails.util.Holders.config.metals
}    

在我的 groovy 代码中。

3.x中对应的方式是什么?

【问题讨论】:

    标签: grails


    【解决方案1】:

    我会先查看升级指南:

    http://docs.grails.org/latest/guide/upgrading.html

    http://docs.grails.org/3.2.0/guide/upgrading.html#upgrading2x

    config.groovy,默认为 application.yml,但你可以将其转换为 application.groovy,外部配置插件中有一个脚本可以帮助解决这个问题:

    http://plugins.grails.org/plugin/grails/external-config

    一般来说,使用持有者是一种回溯实践,最好使用注入的 bean/服务 GrailsApplication grailsApplication

    grailsApplication.config.etc

    或者使用资源在 bean 中连接。使用 holder 的唯一原因是在 grails 之外的另一个对象中,由于某种原因,您不能将其作为 bean 连接起来。在这种情况下,现在有一个 Holders 类,您可以从中获取配置。以下是从 OCI 博客获取配置的其他一些方法:

    http://grailsblog.objectcomputing.com/posts/2016/08/31/retrieving-config-values.html

    【讨论】:

      猜你喜欢
      • 2020-11-24
      • 1970-01-01
      • 1970-01-01
      • 2016-05-22
      • 2014-02-14
      • 1970-01-01
      • 2015-07-01
      • 1970-01-01
      • 2019-05-03
      相关资源
      最近更新 更多