Basic Spring batch tutorial with Maven and Eclipse.

Batch jobs with Spring batch framework is very common and popular. This tutorial assumes that

1) You have set up you Java, Maven, and Eclipse

Once you have followed the following steps, you should have a project structure as shown below.


Step 1: Create a new Maven project with the command shown below.

Step 2: Import it into eclipse IDE via File –> import –> Existing Maven Projects.

Step 3: Update the pom.xml file so that it looks like as shown below.

Step 4: Define the reader and writer files as shown below.


Step 5: Define the batch job and wire the reader and writer via the Spring context file as shown below.


Step 6: Finally, the test class to bootstrap “applicationBatchContext.xml”.

Run the SimpleBatchTest java file right clicking on it and the Run As –> Java Application.


Running more than once can throw JobIsAlreadyRunningException. So, you need to supply different JobParameters as shown below.

The above was run with 3 threads and commit-interval of 1. Experiment by changing the “commit-interval” (aka chunk size) within the step and the “concurrencyLimit” within the SimpleAsyncTaskExecutor in the spring config file.

🔥 300+ Java Interview FAQs

Java & Big Data Tutorials