2013-05-20 35 views
1

在我grials應用我有一個運行工作,這其觸發defenition找到工作觸發值:Grails的 - 從一個配置文件

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

我想改變它的值shouln't是硬編碼,但它們應該從congif/properties文件中獲取。

我嘗試這樣做:

Config.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 '從靜態的上下文。

有沒有人有更好的主意怎麼做?

謝謝。

回答

0

我也發現這個問題,我通常做的是將屬性存儲在.properties文件中,從Quartz作業中刪除觸發器,然後在Bootstrap.groovy中手動引導這些作業,從屬性文件中獲取值。

檢查:Quartz Plugin Documentation來看看如何觸發工作

6

嘗試使用Holders輔助類。

import grails.util.Holders 

static triggers = { 
    simple name: Holders.config.myJob.name, 
    startDelay: Holders.config.myJob.startDelay, 
    repeatInterval: Holders.config.myJob.repeatInterval 
} 
+0

@Dvora這應該被標記爲正確答案。 –

0

你可以使用這樣 $ {} org.codehaus.groovy.grails.commons.ConfigurationHolder.config.myJob.name

+0

你可以添加一些說明爲什麼它應該工作? – Artemix