【发布时间】:2014-06-20 07:22:23
【问题描述】:
我关注 this sample 的 Spring Batch with Boot。
当您运行 main 方法时,作业将被执行。 这样我就无法弄清楚如何控制作业执行。例如,您如何安排作业、访问作业执行或设置作业参数。
我尝试注册自己的 JobLauncher
@Bean
public JobLauncher jobLauncher(JobRepository jobRepo){
SimpleJobLauncher simpleJobLauncher = new SimpleJobLauncher();
simpleJobLauncher.setJobRepository(jobRepo);
return simpleJobLauncher;
}
但是当我尝试在 main 方法中使用它时:
public static void main(String[] args) {
ConfigurableApplicationContext ctx = SpringApplication.run(Application.class, args);
JobLauncher jobLauncher = ctx.getBean(JobLauncher.class);
//try catch removed for readability
jobLauncher.run(ctx.getBean(Job.class), new JobParameters());
}
加载上下文时再次执行该作业,当我尝试手动运行它时得到JobInstanceAlreadyCompleteException。
有没有办法阻止自动执行作业?
【问题讨论】:
标签: java spring spring-batch spring-boot