繁体   English   中英

Spring Batch Job Scheduler

[英]Spring Batch Job Scheduler

有没有办法为通过XML配置的特定Spring Batch作业指定调度程序,而无需使用utils RunScheduler类,例如: https ://www.mkyong.com/spring-batch/spring-batch-and-spring-taskscheduler-example/?

所以现在我的配置看起来像这样:

 <batch:job id="testJob" job-repository="jobRepository" parent="jobParent">
        <batch:step id="testStep" allow-start-if-complete="true">
            <batch:tasklet>
                <batch:chunk
                        reader="testReader"
                        processor="testProcessor"
                        writer="jmsWriter">
                </batch:chunk>
            </batch:tasklet>
        </batch:step>
    </batch:job>


 <task:scheduled-tasks>
        <task:scheduled ref="testJobLauncher" method="runJob" cron="0 */5 * * * *"/>
    </task:scheduled-tasks>

    <bean id="testJobLauncher"
          class="com.test.RunScheduler"
          p:job-ref="testJob"
          p:jobLauncher-ref="jobLauncher"
     "/>



@Component
public class RunScheduler {

    private JobLauncher jobLauncher;
    private Job job;

    public void runJob() {
        try {
            String dateParam = new Date().toString();
                JobParameters param = new JobParametersBuilder().addString("date", dateParam).toJobParameters();
                JobExecution execution = jobLauncher.run(job, param);               
        } catch (Exception e) {
            LOGGER.error("Can't start job", e);
            throw new RuntimeException(e);
        }
    }

    public Job getJob() {
        return job;
    }

    public void setJob(Job job) {
        this.job = job;
    }

    public JobLauncher getJobLauncher() {
        return jobLauncher;
    }

    public void setJobLauncher(JobLauncher jobLauncher) {
        this.jobLauncher = jobLauncher;
    }

}

有没有办法不使用RunScheduler类,而仅使用XML config处理它?

您可以将@EnableScheduling和cronSequenceGenerator的功能用于调度和cron设置,而无需依赖util类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM