【问题标题】:How can I load DSL code from a file during Grails startup?如何在 Grails 启动期间从文件加载 DSL 代码?
【发布时间】:2014-06-20 14:42:26
【问题描述】:

我创建了一个扩展类 BuilderSupport 的 groovy DSL,它现在看起来像这样:

def menu = new MenuBuilder().create {
  item "something.label" : "something"
  item "other.label" : "other"
  item "asd.label": "asd", {
     "test.label": "test"
  }
}

create 并不是一个真正的函数,它只是根节点的标准名称, item "X": "Y" 代表一个菜单项,其中 X 是它的标签,Y 是该项的目标控制器。

DSL 已经在工作了。我的问题是如何制作它,以便您可以简单地在单独的文件中指定 DSL,然后在 Grails 应用程序启动时加载它,类似于 Grails 的 Bean 的 DSL 和约束的 DSL。

该文件中将只有以下代码。

{
  item "something.label" : "something"
  item "other.label" : "other"
  item "asd.label": "asd", {
     "test.label": "test"
  }
}

感谢您的关注

【问题讨论】:

    标签: grails groovy dsl


    【解决方案1】:

    您可以在外部配置文件中指定 DSL,然后在主配置中加载该外部配置。

    DSL 将像所有其他配置一样可用

    这个答案应该会有所帮助:Grails - Cannot read externalized configuration values

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-05
      • 1970-01-01
      • 2021-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多