本文介绍了Spring 4.0.6 with quartz 1.8.6:setCronExpression方法未暴露给CronTriggerBean类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是弹簧版4.0.6和石英,版本1.8.6。问题是,当我尝试使用配置类而不是xml(使用@Configuration注释)时,我无法使用方法设置cron表达式

I am using spring version 4.0.6 and quartz with it, version 1.8.6. The problem is, when I try to use a configuration class instead of xml (with @Configuration annotation), I am not able to set the cron expression with the method

请告诉我是否有版本兼容性问题。

Please tell me if there is a version compatibility issue.

确切的错误是:


推荐答案

考虑使用 CronTriggerFactoryBean

    @Bean
    public CronTriggerFactoryBean cronTriggerFactoryBean() {
        CronTriggerFactoryBean cronTriggerFactoryBean = new CronTriggerFactoryBean();
        cronTriggerFactoryBean.setJobDetail(jobDetailFactoryBean().getObject());
        cronTriggerFactoryBean.setCronExpression("0 35 15 ? * MON *");
        return cronTriggerFactoryBean;
    }
    @Bean
    public JobDetailFactoryBean jobDetailFactoryBean() {
        JobDetailFactoryBean jobDetailFactoryBean = new JobDetailFactoryBean();
        jobDetailFactoryBean.setJobClass(YOUR_CLASS.class);
        return jobDetailFactoryBean;
    }

然后:

CronTrigger trigger = cronTriggerFactoryBean.getObject();

文档说:
注意:这个FactoryBean适用于Quartz 1.x和Quartz 2.0 / 2.1,与旧的CronTriggerBean类形成对比。。

The documentation here says:"NOTE: This FactoryBean works against both Quartz 1.x and Quartz 2.0/2.1, in contrast to the older CronTriggerBean class.".

这篇关于Spring 4.0.6 with quartz 1.8.6:setCronExpression方法未暴露给CronTriggerBean类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 07:09