Excuse me but this may be a noob question for some but it just crossed my mind and I think it is worth to fix my ideas and get a relevant explanation from some experts.
I just started spring batch Tutorial and i have confusion on haw these application are started. let's take this example on official site
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
and the here is the configuration class
@Configuration
@EnableBatchProcessing
public class BatchConfiguration {
@Autowired
public JobBuilderFactory jobBuilderFactory;
@Autowired
public StepBuilderFactory stepBuilderFactory;
@Autowired
public DataSource dataSource;
// tag::jobstep[]
@Bean
public Job importUserJob(JobCompletionNotificationListener listener) {
return jobBuilderFactory.get("importUserJob")
.incrementer(new RunIdIncrementer())
.listener(listener)
.flow(step1())
.end()
.build();
}
@Bean
public Step step1() {
return stepBuilderFactory.get("step1")
.<Person, Person> chunk(10)
.reader(reader())
.processor(processor())
.writer(writer())
.build();
}
// end::jobstep[]
}
Here it was mentioned that the main()
method uses Spring Boot’s SpringApplication.run()
method to launch an application.
it' s not clear for me haw the job importUserJob
was executed whereas
there is no explicit code found that show haw we start this job, it's only a configuration part (declaration).
On the other hand i found another example haw to start a spring application like this:
public static void main(String[] args) {
GenericApplicationContext context = new AnnotationConfigApplicationContext(MyBatchConfiguration.class);
JobLauncher jobLauncher = (JobLauncher) context.getBean("jobLauncher");
Job job = (Job) context.getBean("myJobName");//this is bean name of your job
JobExecution execution = jobLauncher.run(job, jobParameters);
}
Here i can understand that the job is executed with the jobLauncher
.