Spring Book – Chapter 21 – Spring Batch

Spring Batch Quick Start

To quickly setup a Spring Batch job do the following steps as summarized below in the Spring configuration file:

1. Define Spring Batch namespace in your Spring configuration file

Listing 23-20. Defining batch related schema definition in the Spring configuration file

2. Configure appropriate readers, processors and writers

Listing 23-21. Configure FlatFileItemReader and FlatFileItemWriter

3. Configure Job along with Step(s)

Listing 23-22. Configure job along with steps

4. Configure JobLauncher

Listing 23-23. Configure JobLauncher

5. Load and run the job – Once Spring related configuration is done as shown earlier in file applicationContext.xml, call up the Job and JobLauncher and execute the job as shown in Listing 23-24 below.

Listing 23-24. Load and execute job

Spring Batch also provides command-line utility to run the Batch job using the class org.springframework.batch.core.launch.support.CommonLineJobRunner, usage of which is shown below.

6. JobLauncher returns the result – use the “execution” object to see the exit status of the executed job.

Figure 23-14. Working of Spring Batch

Figure 23-14. Working of Spring Batch

Before explaining Figure 23-14 above, I would like to spend some time explaining the various batch idioms which you will come across in Spring Batch. The next section covers these in detail and once this is done in a comprehensive manner, we will come back to the Figure 23-14 and explain it completely in all aspects.

Page Visitors: 24109

The following two tabs change content below.
Tomcy John

Tomcy John

Blogger & Author at javacodebook
He is an Enterprise Java Specialist holding a degree in Engineering (B-Tech) with over 10 years of experience in several industries. He's currently working as Principal Architect at Emirates Group IT since 2005. Prior to this he has worked with Oracle Corporation and Ernst & Young. His main specialization is on various web technologies and acts as chief mentor and Architect to facilitate incorporating Spring as Corporate Standard in the organization.
Tomcy John

Latest posts by Tomcy John (see all)

2 thoughts on “Spring Book – Chapter 21 – Spring Batch

  1. Thanks for sharing the information but what’s the difference between CursorItemReader’s setFetchSize() and PagingItemReader’s setPageSize()? isn’t it the same?

  2. Please provide an example for StoredProcedureItem Reader – which returns cursor and how to process cursor in processor – I am new to Spring Batch as part of my work I need to invoke Oracle Stored proc which takes one param as input and returns result set which I need to process in Spring Batch Processor.


Leave a Reply

Your email address will not be published. Required fields are marked *