spring+quartz2.2.1加载数据库任务出现的异常,求大神解答~

发布于 2021-11-23 05:37:29 字数 6049 浏览 964 评论 4

环境: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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

坐在坟头思考人生 2021-11-29 14:58:33

你的使用方法应该是搞错了同学。

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;]

初始化的时候已经出错了。

成熟的代价 2021-11-29 14:34:34

为啥呀,本人菜鸟求解答

如此安好 2021-11-28 23:34:47

回复
你终于把报错信息帖出来了。 这下能解答了。

够钟 2021-11-24 08:10:34

哈哈~ oschina页面提交有快捷键可能直接提交了

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文