quartz初始化出错

项目中有定时任务的需求,把quartz整合进来后,开始执行任务的时候出错。
配置文件如下:










<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
    <property name="jobDetail" ref="jobDetail"/>  
    <property name="cronExpression" value="0 * * *,* * ?"/>   
</bean>

<bean id="jobDetail" class="org.springframework.scheduling.quartz.JobDetailBean">
     <property name="jobClass" value="test.SendTicket"/>
     <property name="jobDataAsMap">
         <map><entry key="size" value="10"/></map>
     </property>
     <property name="applicationContextJobDataKey" value="applicationContext"/>
</bean>
<bean id="servletContext" class="org.springframework.web.context.support.ServletContextFactoryBean"/>

任务代码:

public class SendTicket {

@SuppressWarnings("unchecked")
public void execute(JobExecutionContext jctx) throws JobExecutionException {
    Map dataMap=jctx.getJobDetail().getJobDataMap();
    String size =(String)dataMap.get("size"); 
    System.out.println("size="+size);
}

}

错误信息为:
An error occured instantiating job to be executed. job= 'DEFAULT.jobDetail'
org.quartz.SchedulerException: Job instantiation failed [See nested exception: java.lang.IllegalArgumentException: Unable to execute job class [test.SendTicket]: only [org.quartz.Job] and [java.lang.Runnable] supported.]
at org.springframework.scheduling.quartz.AdaptableJobFactory.newJob(AdaptableJobFactory.java:41)
at org.quartz.core.JobRunShell.initialize(JobRunShell.java:132)
at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:386)
Caused by: java.lang.IllegalArgumentException: Unable to execute job class [test.SendTicket]: only [org.quartz.Job] and [java.lang.Runnable] supported.
at org.springframework.scheduling.quartz.AdaptableJobFactory.adaptJob(AdaptableJobFactory.java:74)
at org.springframework.scheduling.quartz.AdaptableJobFactory.newJob(AdaptableJobFactory.java:38)
... 2 more

1个回答

java.lang.IllegalArgumentException: Unable to execute job class [test.SendTicket]: only [org.quartz.Job] and [java.lang.Runnable] supported.]

看到异常信息没,test.SendTicket这个类要实现org.quartz.Job接口或java.lang.Runnable

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问