Am using the Quartz plugin for Grails and have a simple job:
class MyJob{
static triggers = {
cron name: 'MyJobTrigger', cronExpression: '0 0/1 * * * ?'
}
def execute(){
println "do some work"
}
}
All works fine, job fires off every minute as expected.
Now I want the want the cron expression to be property driven so I can override in different environments. So Config.groovy contains the default value:
myJob.cron = '0 0/1 * * * * ?'
And I change my class to have:
GrailsApplication grailsApplication
static triggers = {
cron name: 'MyJobTrigger', cronExpression: grailsApplication.config.myJob.cron
}
When I run my code, I get this error:
Caused by MissingPropertyException: No such property: grailsApplication for class: MyJob
Assuming this is something to do with the way the MyJob class is loaded/initialised, the static triggers created before the GrailsApplication is injected??? This use of GrailsApplication is the usual way I get project properties.
How else can I have a property driven cron trigger?