spring+quartz2.2.1加载数据库任务出现的异常,求大神解答~
环境:ssi+quartz2.2.1
异常:
2015-05-21 17:57:20 ERROR ErrorLogger:2425 - An error occured instantiating job to be executed. job= 'c.a' org.quartz.SchedulerException: Problem instantiating class 'com.springQuartz.support.QuartzJobFactory' - [See nested exception: java.lang.AbstractMethodError: org.springframework.scheduling.quartz.AdaptableJobFactory.newJob(Lorg/quartz/spi/TriggerFiredBundle;Lorg/quartz/Scheduler;)Lorg/quartz/Job;] at org.quartz.core.JobRunShell.initialize(JobRunShell.java:134) at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:375) Caused by: java.lang.AbstractMethodError: org.springframework.scheduling.quartz.AdaptableJobFactory.newJob(Lorg/quartz/spi/TriggerFiredBundle;Lorg/quartz/Scheduler;)Lorg/quartz/Job; at org.quartz.core.JobRunShell.initialize(JobRunShell.java:127) ... 1 more 2015-05-21 17:57:20 INFO RAMJobStore:1615 - All triggers of Job c.a set to ERROR state. 2015-05-21 17:57:20 DEBUG QuartzSchedulerThread:276 - batch acquisition of 1 triggers 2015-05-21 17:57:20 ERROR ErrorLogger:2425 - An error occured instantiating job to be executed. job= 't.test' org.quartz.SchedulerException: Problem instantiating class 'com.springQuartz.support.QuartzJobFactoryDisallowConcurrentExecution' - [See nested exception: java.lang.AbstractMethodError: org.springframework.scheduling.quartz.AdaptableJobFactory.newJob(Lorg/quartz/spi/TriggerFiredBundle;Lorg/quartz/Scheduler;)Lorg/quartz/Job;] at org.quartz.core.JobRunShell.initialize(JobRunShell.java:134) at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:375) Caused by: java.lang.AbstractMethodError: org.springframework.scheduling.quartz.AdaptableJobFactory.newJob(Lorg/quartz/spi/TriggerFiredBundle;Lorg/quartz/Scheduler;)Lorg/quartz/Job; at org.quartz.core.JobRunShell.initialize(JobRunShell.java:127) ... 1 more 2015-05-21 17:57:20 INFO RAMJobStore:1615 - All triggers of Job t.test set to ERROR state. 2015-05-21 17:57:20 DEBUG QuartzSchedulerThread:276 - batch acquisition of 1 triggers 2015-05-21 17:57:20 ERROR ErrorLogger:2425 - An error occured instantiating job to be executed. job= 'f.test1' org.quartz.SchedulerException: Problem instantiating class 'com.springQuartz.support.QuartzJobFactory' - [See nested exception: java.lang.AbstractMethodError: org.springframework.scheduling.quartz.AdaptableJobFactory.newJob(Lorg/quartz/spi/TriggerFiredBundle;Lorg/quartz/Scheduler;)Lorg/quartz/Job;]初始化代码:
public void init() throws Exception { System.out.println("加载数据库任务开始"); List<ScheduleJob> jobList = this.queryForlist("com.springQuartz.entity.ScheduleJob.getAll", null) ; for (ScheduleJob job : jobList) { addJob(job); } }
public void addJob(ScheduleJob job) throws SchedulerException { if (job == null || !ScheduleJob.STATUS_RUNNING.equals(job.getJobStatus())) { return; } //Scheduler scheduler = schedulerFactoryBean.getScheduler(); log.debug(scheduler + ".......................................................................................add"); TriggerKey triggerKey = TriggerKey.triggerKey(job.getJobName(), job.getJobGroup()); CronTrigger trigger = (CronTrigger) scheduler.getTrigger(triggerKey); // 不存在,创建一个 if (null == trigger) { Class clazz = ScheduleJob.CONCURRENT_IS.equals(job.getIsConcurrent()) ? QuartzJobFactory.class : QuartzJobFactoryDisallowConcurrentExecution.class; JobDetail jobDetail = JobBuilder.newJob(clazz).withIdentity(job.getJobName(), job.getJobGroup()).build(); jobDetail.getJobDataMap().put("scheduleJob", job); CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression()); trigger = TriggerBuilder.newTrigger().withIdentity(job.getJobName(), job.getJobGroup()).withSchedule(scheduleBuilder).build(); scheduler.scheduleJob(jobDetail, trigger); }else { // Trigger已存在,那么更新相应的定时设置 CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(job.getCronExpression()); // 按新的cronExpression表达式重新构建trigger trigger = trigger.getTriggerBuilder().withIdentity(triggerKey).withSchedule(scheduleBuilder).build(); // 按新的trigger重新设置job执行 scheduler.rescheduleJob(triggerKey, trigger); } }
以上debug跟踪没有出现异常
QuartzJobFactory。java
import org.apache.log4j.Logger; import org.quartz.Job; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import com.springQuartz.entity.ScheduleJob; public class QuartzJobFactory implements Job{ public final Logger log = Logger.getLogger(this.getClass()); public QuartzJobFactory(){ } @Override public void execute(JobExecutionContext context) throws JobExecutionException { System.out.println("-----------------------------"); ScheduleJob scheduleJob = (ScheduleJob) context.getMergedJobDataMap().get("scheduleJob"); TaskUtils.invokMethod(scheduleJob); } }
spring.xml配置
<!-- 数据库配置文件位置 --> <context:property-placeholder location="classpath:jdbc.properties" /> <!-- 调度相关 --> <bean id="springUtils" class="com.springQuartz.support.SpringUtils" /> <bean id="schedulerFactoryBean" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" /> <!-- 启动加载加载数据库任务 --> <bean id="jobService" class="com.springQuartz.service.ScheduleJobServiceImpl" init-method="init"> <property name="scheduler" ref="schedulerFactoryBean" /> <property name="dao" ref="dao" /> </bean>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
你的使用方法应该是搞错了同学。
Problem instantiatingclass 'com.springQuartz.support.QuartzJobFactory' - [See nested exception: java.lang.AbstractMethodError: org.springframework.scheduling.quartz.AdaptableJobFactory.newJob(Lorg/quartz/spi/TriggerFiredBundle;Lorg/quartz/Scheduler;)Lorg/quartz/Job;]
初始化的时候已经出错了。
为啥呀,本人菜鸟求解答
回复
你终于把报错信息帖出来了。 这下能解答了。
哈哈~ oschina页面提交有快捷键可能直接提交了