Spring - Quartz没有执行jobclass

时间:2015-10-14 13:50:00

标签: java spring quartz-scheduler

我试图用石英和弹簧来完成一项工作,但是没有运行这项工作,也没有在控制台上出错。该作业保存在mysql中,但不会运行。

我的配置是

  • spring 4.0.6
  • quartz 2.2.1

的applicationContext.xml

<bean id="scheduler" name="scheduler"
    class="org.springframework.scheduling.quartz.SchedulerFactoryBean"
    scope="singleton">
    <property name="quartzProperties">
        <props>
            <prop key="org.quartz.scheduler.instanceId">AUTO</prop>
            <prop key="org.quartz.scheduler.instanceName">MyClusteredScheduler</prop>
            <prop key="org.quartz.jobStore.class">org.quartz.impl.jdbcjobstore.JobStoreTX</prop>
            <prop key="org.quartz.jobStore.driverDelegateClass">org.quartz.impl.jdbcjobstore.StdJDBCDelegate</prop>
            <prop key="org.quartz.jobStore.tablePrefix">QRTZ_</prop>
            <prop key="org.quartz.jobStore.isClustered">true</prop>
            <prop key="org.quartz.jobStore.clusterCheckinInterval">20000</prop>
            <prop key="org.quartz.jobStore.misfireThreshold">60000</prop>
        </props>
    </property>
    <property name="dataSource">
        <ref bean="dataSource" />
    </property>
</bean>
<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver" />
    <property name="url" value="jdbc:mysql://localhost:3306/test" />
    <property name="username" value="*****" />
    <property name="password" value="*****" />
</bean>

MyJob类

public class MyJob implements Job, Serializable{
    private static final long serialVersionUID = -1750295779628942902L;

    public void execute(JobExecutionContext context) throws JobExecutionException {
        System.out.println("run job run!!!");
    }
}

主要测试类

public static void main(String[] args) {
    ClassPathXmlApplicationContext context=new ClassPathXmlApplicationContext("applicationContext.xml");
    StdScheduler stdScheduler= (StdScheduler) context.getBean("scheduler");
    MyJob myJob= (MyJob) context.getBean("myJob");
    try {
        JobDetail jobDetail = JobBuilder.newJob(MyJob.class).withIdentity("triggerUno10").build();  
        Trigger trigger= TriggerBuilder.newTrigger().withIdentity("triggerUno10").withSchedule(
                                    CronScheduleBuilder.cronSchedule("0/5 * * * * ?")).forJob(jobDetail).build(); 
        stdScheduler.start();
        stdScheduler.scheduleJob(jobDetail, trigger);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

1 个答案:

答案 0 :(得分:1)

问题是石英版在某种程度上不能与spring4.0.6一起使用,以解决我已将石英降级到2.1.7而且它有效。