1

在我的 grials 应用程序中,我有一个正在运行的工作,这就是它的触发防御:

    static triggers = {
    simple name: 'myJob', startDelay: 1000, repeatInterval: 36000000   
    }

我想改变它,不应该对值进行硬编码,但它们应该取自 congif/properties 文件。

我试过这个:

配置.groovy:

myJob {
simpleName = 'myJob'
startDelay = '1000'
repeatInterval = '36000000'
}

并在工作触发器中:

    static triggers = {
    simple name: grailsApplication.config.myJob.name, startDelay: grailsApplication.config.myJob.startDelay, repeatInterval: grailsApplication.config.myJob.repeatInterval   
    }

但随后我收到一条消息:无法从静态上下文中引用非静态符号“grailsApplication”。

有没有人有更好的想法如何做到这一点?

谢谢。

4

3 回答 3

6

尝试使用Holders助手类。

import grails.util.Holders

static triggers = {
     simple name: Holders.config.myJob.name, 
     startDelay: Holders.config.myJob.startDelay, 
     repeatInterval: Holders.config.myJob.repeatInterval   
}
于 2013-05-20T15:23:25.213 回答
0

你可以像这样使用 ${org.codehaus.groovy.grails.commons.ConfigurationHolder.config.myJob.name}

于 2013-07-26T09:33:06.410 回答
0

我也发现了这个问题,我通常做的是将属性存储在 .properties 文件中,从 Quartz 作业中删除触发器,然后在 Bootstrap.groovy 中手动引导这些作业,从属性文件中获取值。

检查这个:Quartz 插件文档以查看如何触发作业

于 2013-05-20T08:41:13.430 回答