작성
·
309
0
@Bean
public Job jobOperationJob() {
return jobBuilderFactory.get("jobOperationJob")
.incrementer(new RunIdIncrementer())
.start(step1())
.next(step2())
.build();
}
@PostMapping("/batch/start")
public String start(@RequestBody JobInfo jobInfo) throws NoSuchJobException, JobInstanceAlreadyExistsException, JobParametersInvalidException, InterruptedException {
// jobName은 jobRegistry에서 구할 수 있음.
Collection<String> jobNames = jobRegistry.getJobNames();
for (String jobName : jobNames) {
SimpleJob job = (SimpleJob) jobRegistry.getJob(jobName); // SimpleJob으로 다운 캐스팅
System.out.println("jobName : " + jobName);
jobOperator.start(job.getName(), "id=" + jobInfo.getId());
}
return "batch is started";
}
답변 1
0