Spring identifies the job on the event when we try starting the job. Below is a small snippet for reference,
This is a bean definition which returns of type Job and contains all the orchestration of steps in it,
@Bean
public Job testJob() throws Exception {
Job job = jobBuilderFactory.get("testJob").incrementer(new RunIdIncrementer())
.start(step1()).next(step2()).next(step3()).end()
.listener(jobCompletionListener()).build();
ReferenceJobFactory referenceJobFactory = new ReferenceJobFactory(job);
registry.register(referenceJobFactory);
return job;
}
Below would make use of the bean and start the job which means that the workflow defined as a part of job would get executed,
@Autowired
JobLauncher jobLauncher;
@Autowired
Job testJob;
// eliminating the method defnition for simplicity,
try {
jobLauncher.run(testJob, jobParameters);
} catch (Exception e) {
logger.error("Exception while running a batch job {}", e.getMessage());
}