Evg*_*rov 41 java spring spring-batch 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
当我尝试手动运行时,我得到了该作业.有没有办法阻止自动执行作业?
Evg*_*rov 55
可以通过设置来防止作业执行
spring.batch.job.enabled=false
Run Code Online (Sandbox Code Playgroud)
在application.properties中.或者您可以使用spring.batch.job.names
它将以逗号分隔的作业名称列表运行.
从这里开始:如何在执行代码时第一次停止弹出批量预定作业?
归档时间: |
|
查看次数: |
26458 次 |
最近记录: |