0

嗨,我希望我的应用程序的用户通过 IHM 选择一个表达式并配置一项服务,实际上我每小时配置一次石英,它运行良好,但是当我试图让用户配置执行任务编号的时间时通过了,我用了这段代码:

public void collectorCronScheduling(String expression) {
    try {
        triggerBean.setCronExpression(expression);
        triggerBean.validate();
        System.out.println("cron expression modifiée");
        schedulerFactoryBean.start();
        System.out.println("scheduler started");
    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SchedulerException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

public CronTriggerBean getTriggerBean() {
    return triggerBean;
}

public void setTriggerBean(CronTriggerBean triggerBean) {
    this.triggerBean = triggerBean;
}

public SchedulerFactoryBean getSchedulerFactoryBean() {
    return schedulerFactoryBean;
}

public void setSchedulerFactoryBean(
        SchedulerFactoryBean schedulerFactoryBean) {
    this.schedulerFactoryBean = schedulerFactoryBean;
}

这是 applicationContext.xml

<bean id="collectorTicketServiceImplJob"
        class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="collectorTicketServiceImpl" />
        <property name="targetMethod" value="ExtractTicketFromMail" />
    </bean>

    <bean id="collectorTicketServiceImplTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">

        <property name="jobDetail" ref="collectorTicketServiceImplJob" />
        <property name="cronExpression" value="0 0/30 * * * ?" />
    </bean>


    <bean id="collectorTicketServiceImplTriggerSchedular"
        class="org.springframework.scheduling.quartz.SchedulerFactoryBean">

        <property name="triggers">
            <list>
                <ref bean="collectorTicketServiceImplTrigger" />
            </list>
        </property>
    </bean>
4

0 回答 0