相关疑难解决方法(0)

Spring Boot如何运行批处理作业

我按照这个样本进行Spring Batch with Boot.

运行main方法时,将执行作业.这样我就无法弄清楚如何控制作业执行.例如,您如何安排作业,或访问作业执行或设置作业参数.

我试着注册我自己的JobLauncher

@Bean
public JobLauncher jobLauncher(JobRepository jobRepo){
    SimpleJobLauncher simpleJobLauncher = new SimpleJobLauncher();
    simpleJobLauncher.setJobRepository(jobRepo);
    return simpleJobLauncher;
}
Run Code Online (Sandbox Code Playgroud)

但是当我尝试在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());   
}
Run Code Online (Sandbox Code Playgroud)

加载上下文后再次执行作业,JobInstanceAlreadyCompleteException当我尝试手动运行时,我得到了该作业.有没有办法阻止自动执行作业?

java spring spring-batch spring-boot

41
推荐指数
1
解决办法
3万
查看次数

标签 统计

java ×1

spring ×1

spring-batch ×1

spring-boot ×1