Grails3 application.groovy动态属性

时间:2017-04-25 15:31:21

标签: grails grails-2.0 grails-3.0

在Grails 2中,我们使用内部库来动态设置Config.groovy文件中的属性值。该库查看了特定于环境的配置管理数据库并填充了这些值。这是在Grails 2中运行的配置示例

import com.mycompany.otherproject.ConfigurationManagement   

family {
    dynamic.property = ConfigurationManagement.getValue("dynamic.property.name", "default")
    static.proprty = "static value"
}

根据Upgrading from Grails 2.x - Reference Documentation,我将此信息复制到application.groovy,但现在我收到以下错误,我无法解决。

Error |
Error occurred running Grails CLI: startup failed:
script14930638938641309394273.groovy: 1: unable to resolve class com.mycompany.otherproject.ConfigurationManagement
 @ line 1, column 1.
   import com.mycompany.otherproject.ConfigurationManagement
   ^

建议?

1 个答案:

答案 0 :(得分:0)

事实证明,您无法直接设置属性,但可以声明局部变量,然后使用该值设置属性。

import com.mycompany.otherproject.ConfigurationManagement   

def dynamicProperty = ConfigurationManagement.getValue("dynamic.property.name", "default")

family {
    dynamic.property = dynamicProprty
    static.proprty = "static value"
}