ECM
ECM
总版主
总版主
  • 社区居民
  • 忠实会员
  • 原创写手
阅读:710回复:0

Spring 4.0.6 with quartz 1.8.6 : setCronExpression method is not exposed to CronTriggerBean class

楼主#
更多 发布于:2016-05-16 10:53
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 CronTriggerBean ctBean = new CronTriggerBean(); ctBean.setCronExpression("0 35 15 ? * MON *"); Please tell me if there is a version compatibility issue. The exact error is this: The method setCronExpression(String) is undefined for the type CronTriggerBean
answer(解决方案):

Consider using 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;
    }
 and then: CronTrigger trigger = cronTriggerFactoryBean.getObject();
 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.".

 

 

 

 

 

 

 

异常中心网是一家专门收集整理程序员编程过程中遇到的常见异常(exception)以及各种异常问答中心的网站。异常中心网旨在,减少程序员在编码遇到异常,处理各种异常时间和痛苦,让程序员能更愉快的、快速的定位异常并查找对应的异常解决方案。异常中心网诚心打造最完美的编程社区为程序员用户服务,努力成为最好的程序员乐园程序员社区程序异常中心程序bug中心异常问答中心

 

喜欢0 评分0
游客

返回顶部