编程语言
首页 > 编程语言> > java-带有石英1.8.6的Spring 4.0.6:setCronExpression方法未公开给CronTriggerBean类

java-带有石英1.8.6的Spring 4.0.6:setCronExpression方法未公开给CronTriggerBean类

作者:互联网

我使用的是Spring 4.0.6版,而石英使用的是1.8.6版.问题是,当我尝试使用配置类而不是xml(带有@Configuration批注)时,无法使用该方法设置cron表达式

CronTriggerBean ctBean = new CronTriggerBean();
ctBean.setCronExpression(“0 35 15 ? * MON *”);

请告诉我是否存在版本兼容性问题.

确切的错误是这样的:

The method setCronExpression(String) is undefined for the type CronTriggerBean

解决方法:

考虑使用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();

here文档说:
“注意:与较早的CronTriggerBean类相反,此FactoryBean可同时用于Quartz 1.x和Quartz 2.0 / 2.1.”

标签:java,spring,spring-mvc,quartz-scheduler
来源: https://codeday.me/bug/20191013/1906270.html