将spring3升级到spring4.2 后使用定时任务quartz报错
<beanid="jobFactory"class="com.dc.pmcore.publicmodule.entity.timedtask.MyJobFactory">...
<bean id="jobFactory" class="com.dc.pmcore.publicmodule.entity.timedtask.MyJobFactory"></bean>
<bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobFactory" ref="jobFactory"/>
<property name="triggers">
<list>
<ref bean="cronTrigger"/>
<!-- <ref local="projectAnalyseTrigger"/>
<ref local="stdReportScheduleWeek"/>
<ref local="projectAnalyseTrigger"/>
<ref local="warpNotifyTriger"/>
<ref local="dayNotifyTriger"/>
<ref local="stdReportScheduleWeek"/>-->
</list>
</property>
</bean>
<bean id="schedulerManagerEngine" class="com.dc.flamingo.tools.quartz.SchedulerManagerEngine">
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="schedulerJobInitEngine"/>
<property name="cronExpression">
<value>0/20 * * * * ?</value>
</property>
</bean>
<bean id="schedulerJobInitEngine" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="schedulerManagerEngine"/>
<property name="targetMethod" value="initJobTrigger"/>
<property name="concurrent" value="false"/>
<!-- <property name="durability" value="true"/> -->
</bean>
这是配置文件
private void loadScheduler(SchedulerBean schedulerBean)
throws ParseException, SchedulerException
{
this.jobDetailBean = new JobDetailFactoryBean();
this.cronTriggerBean = new CronTriggerFactoryBean();
this.jobDetailBean = ((JobDetailFactoryBean)ContextHolder.getBean(schedulerBean.getSchedulerId()));
this.cronTriggerBean.setCronExpression(schedulerBean.getExecuteTime());
this.cronTriggerBean.setJobDetail(this.jobDetailBean.getObject());
this.cronTriggerBean.setName(schedulerBean.getSchedulerId());
this.cronTriggerBean.setGroup("DEFAULT");
this.schedulerJob.scheduleJob(this.jobDetailBean.getObject(), this.cronTriggerBean.getObject());
getSchedulerService().saveExecuteTime(schedulerBean.getSchedulerId(), schedulerBean.getLastExecuteTime(), DateUtils.convertDateTimeToString(this.cronTriggerBean.getObject().getNextFireTime()));
}
在 this.jobDetailBean = ((JobDetailFactoryBean)ContextHolder.getBean(schedulerBean.getSchedulerId()));
这行报org.quartz.impl.JobDetailImpl cannot be cast to org.springframework.scheduling.quartz.JobDetailFactoryBean 展开
<bean id="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="jobFactory" ref="jobFactory"/>
<property name="triggers">
<list>
<ref bean="cronTrigger"/>
<!-- <ref local="projectAnalyseTrigger"/>
<ref local="stdReportScheduleWeek"/>
<ref local="projectAnalyseTrigger"/>
<ref local="warpNotifyTriger"/>
<ref local="dayNotifyTriger"/>
<ref local="stdReportScheduleWeek"/>-->
</list>
</property>
</bean>
<bean id="schedulerManagerEngine" class="com.dc.flamingo.tools.quartz.SchedulerManagerEngine">
</bean>
<bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail" ref="schedulerJobInitEngine"/>
<property name="cronExpression">
<value>0/20 * * * * ?</value>
</property>
</bean>
<bean id="schedulerJobInitEngine" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject" ref="schedulerManagerEngine"/>
<property name="targetMethod" value="initJobTrigger"/>
<property name="concurrent" value="false"/>
<!-- <property name="durability" value="true"/> -->
</bean>
这是配置文件
private void loadScheduler(SchedulerBean schedulerBean)
throws ParseException, SchedulerException
{
this.jobDetailBean = new JobDetailFactoryBean();
this.cronTriggerBean = new CronTriggerFactoryBean();
this.jobDetailBean = ((JobDetailFactoryBean)ContextHolder.getBean(schedulerBean.getSchedulerId()));
this.cronTriggerBean.setCronExpression(schedulerBean.getExecuteTime());
this.cronTriggerBean.setJobDetail(this.jobDetailBean.getObject());
this.cronTriggerBean.setName(schedulerBean.getSchedulerId());
this.cronTriggerBean.setGroup("DEFAULT");
this.schedulerJob.scheduleJob(this.jobDetailBean.getObject(), this.cronTriggerBean.getObject());
getSchedulerService().saveExecuteTime(schedulerBean.getSchedulerId(), schedulerBean.getLastExecuteTime(), DateUtils.convertDateTimeToString(this.cronTriggerBean.getObject().getNextFireTime()));
}
在 this.jobDetailBean = ((JobDetailFactoryBean)ContextHolder.getBean(schedulerBean.getSchedulerId()));
这行报org.quartz.impl.JobDetailImpl cannot be cast to org.springframework.scheduling.quartz.JobDetailFactoryBean 展开
1个回答
2016-12-16
展开全部
这个问题应该是jar不兼容的问题!
Spring针对quartz的支持是有严格的版本要求的 一般都是spring3.2.2配quartz2.2.1那一整套最稳定,但是Spring不同的版本的quartz,spring就不行了,里面针对spring中的JobDetailFactoryBean类不支持,详细情况需要你可以在百度中搜索【spring配quartz版本】 里面有几个帖子是不错的。
Spring针对quartz的支持是有严格的版本要求的 一般都是spring3.2.2配quartz2.2.1那一整套最稳定,但是Spring不同的版本的quartz,spring就不行了,里面针对spring中的JobDetailFactoryBean类不支持,详细情况需要你可以在百度中搜索【spring配quartz版本】 里面有几个帖子是不错的。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询