我在grails项目中安装了Quartz Plugin但是当我编译时,它给了我以下错误。
Error loading plugin manager: startup failed:
C:\Users\X\.grails\1.3.7\projects\Val\plugins\quartz-0.4.2\QuartzGrailsPlugin.groovy: 116: You cannot create an instance from the abstract interface 'org.quartz.CronTrigger'.
@ line 116, column 35.
Trigger trigger = new CronTrigger(generateTriggerName(), GTCP.DEFAULT_TRIGGERS_GROUP, jobName, jobGroup, cronExpression)
^
C:\Users\X\.grails\1.3.7\projects\Val\plugins\quartz-0.4.2\QuartzGrailsPlugin.groovy: 122: You cannot create an instance from the abstract interface 'org.quartz.SimpleTrigger'.
@ line 122, column 35.
Trigger trigger = new SimpleTrigger(generateTriggerName(), GTCP.DEFAULT_TRIGGERS_GROUP, jobName, jobGroup, new Date(), null, repeatCount, interval)
^
C:\Users\X\.grails\1.3.7\projects\Val\plugins\quartz-0.4.2\QuartzGrailsPlugin.groovy: 128: You cannot create an instance from the abstract interface 'org.quartz.SimpleTrigger'.
@ line 128, column 35.
Trigger trigger = new SimpleTrigger(generateTriggerName(), GTCP.DEFAULT_TRIGGERS_GROUP, jobName, jobGroup, scheduleDate, null, 0, 0)
^
C:\Users\X\.grails\1.3.7\projects\Val\plugins\quartz-0.4.2\QuartzGrailsPlugin.groovy: 133: You cannot create an instance from the abstract interface 'org.quartz.SimpleTrigger'.
@ line 133, column 35.
Trigger trigger = new SimpleTrigger(generateTriggerName(), GTCP.DEFAULT_TRIGGERS_GROUP, jobName, jobGroup, scheduleDate, null, 0, 0)
^
4 errors
这就是我想要实现的目标......
class MyJob {
static triggers = {
cron name: 'myTrigger', cronExpression: "0 0 6 * * ?"
}
def group = "MyGroup"
def execute(){
print "Job run!"
}
}
注意:插件版本为0.4.2
答案 0 :(得分:2)
我真的无法重现它。我创建了一个新项目并安装了插件,它运行得很好。你不是要创建一个MyJob类的实例,对吗?基本上,一旦安装,这个类(作业)就可以运行了。它将根据cronExpression上的设置被触发。
以下是我测试您的方案的步骤:
1)创建grails app:
grails create-app testquartz
2)安装插件:
grails install-plugin quartz
3)创建一份新工作:
grails create-job my
4)编辑MyJob类:
class MyJob {
static triggers = {
cron name: 'myTrigger', cronExpression: "* * * * * ?"
}
def group = "MyGroup"
def execute(){
print "Job run!"
}
}
5)运行应用程序:
grails run-app
=>您应该看到每秒打印出一个“作业运行”文本,因为cronExpression会每秒触发它。在execute()中,您可以放置要由cron作业执行的代码。我建议创建一个服务并将代码放在服务中运行并在execute()方法中调用它。