I am learning about spring batch and was following the guide from https://spring.io/guides/gs/batch-processing/
I figured that to stop the spring batch from starting automatically when firing up the app, I have to set spring.batch.job.enabled=false
My question is how do I manually trigger it? I tried the below to trigger the job after a return key is pressed in console but it is not working(It was working with spring.batch.job.enabled=true and without the JobLauncherController class)
@SpringBootApplication
public class BatchProcessingApplication {
public static void main(String[] args) throws Exception
{
SpringApplication.run(BatchProcessingApplication.class, args);
new Scanner(System.in).nextLine();
new JobLauncherController().launchJob();
}
}
@Controller
public class JobLauncherController {
@Autowired
JobLauncher jobLauncher;
@Autowired
Job importUserJob;
public void launchJob() throws Exception{
JobParameters parameters = new JobParametersBuilder()
.addLong("run.id", new Date().getTime()).toJobParameters();
jobLauncher.run(importUserJob, parameters);
}