Launch Spring Batch job from a REST endpoint 🚀

theoneamin
2 min readMay 9, 2022

In this article, we’ll take a look at how to launch a spring batch job from a REST endpoint. We’ll do this by first disabling jobs from running automatically and then using a job launcher to start the job whenever we hit an endpoint.

We will not go into details about how we create the batch application so if you want to find out more about doing that you can check out this article https://theoneamin.medium.com/how-to-send-bulk-emails-using-spring-batch-5222eca5d7d4.

Batch overview

We have a batch application that has one job with one step which processes an excel file. The job will read a file name from the job parameters, find the file from a folder, and start processing the file.

Above is just part of the code I believe would help give background understanding but is not all the code needed to make this work. You can find the complete code on this repo https://github.com/mamin11/fileprocessor

In application.properties, add the following

spring.batch.job.enabled=false

REST endpoint

In my controller, I’ve autowired the following.

--

--