Transforming items using ItemProcessor

In this post under Spring Batch, I will explain how to achieve Item Transformation using ItemProcessor interface. Item Transformation process transforms the items read by reader before sending them to the writer. The transformation involves changing the state of the read itemor creating a completely new object. In the second case, the written item type…… Continue reading Transforming items using ItemProcessor

Using custom delimiter while reading and writing batch file

In all previous Spring Batch posts, the DelimitedLineAggregator(which creates String format of java objects) and DelimitedLineTokenizer (which extracts fields from each record) assume ‘,’ as delimiter as shown below EMP_ID0,EMP_NAME0,EMP_STATUS0,0EMP_ID1,EMP_NAME1,EMP_STATUS1,1EMP_ID2,EMP_NAME2,EMP_STATUS2,2EMP_ID3,EMP_NAME3,EMP_STATUS3,3 We can use other symbols as delimiter and inform DelimitedLineAggregator and DelimitedLineTokenizer about this. At the time of reading and writing, the default delimiter is…… Continue reading Using custom delimiter while reading and writing batch file

Validating JobParameters using JobParametersValidator interface

In this post under Spring Batch, I will explain how to validate the parameters passed to the job instance. The interface we will be using for validating the Job parameters is org.springframework.batch.core.JobParametersValidator which has only one method as shown below public interface JobParametersValidator { void validate(JobParameters parameters) throws JobParametersInvalidException; } Based on the signature of…… Continue reading Validating JobParameters using JobParametersValidator interface

Passing Job Parameters using JobParametersBuilder

In this post under Spring Batch I will explain how to pass parameters to a job. We will take the help of org.springframework.batch.core.JobParametersBuilder class which follows Builder design pattern. We will use JobParametersBuilder class to build the job parameters. Then we pass the job parameters along with the job (to be executed) as parameters to…… Continue reading Passing Job Parameters using JobParametersBuilder

Chaining multiple ItemProcessor

In this post of Spring Batch, I will explain with an example how to chain multiple ItemProcessors. For my example, I will create an ItemProcessor which will go through employee records one item at a time and filter out odd records. Below is the code of the ItemProcessor package xml.package11; import org.springframework.batch.item.ItemProcessor; public class EmployeeFilterItemProcessor…… Continue reading Chaining multiple ItemProcessor

ItemReadListener, ItemWriteListener, and ItemProcessListener Example

In this post under Spring Batch, I will explain how to create listeners during 1) reading of an item2) writing of an items3) processing of an item with an example. We create listeners by implementing the three interfaces ItemReadListener, ItemWriteListener, and ItemProcessListener. The class that implements ItemReadListener<T> interface must provide implementation for the below three…… Continue reading ItemReadListener, ItemWriteListener, and ItemProcessListener Example

Adding Step Level Listeners using StepExecutionListener

In this post of Spring Batch, I will explain how to add step level listeners. Spring Batch provides a facility to add listeners at step level. The listeners are executed before the step is started and after the step is finished. This post explains how to create step level listeners and integrate them with the…… Continue reading Adding Step Level Listeners using StepExecutionListener

Reading from multiple files using MultiResourceItemReader

In this post of Spring Batch, I will explain how to read from multiple files. We take the help of org.springframework.batch.item.file.MultiResourceItemReader, it reads from multiple file. The MultiResourceItemReader takes two arguments1) list of resources or pattern followed by the multiple source files, from which the data has to be read2) Reference to reader bean which…… Continue reading Reading from multiple files using MultiResourceItemReader

Writting to multiple files using MultiResourceItemWriter

In this post of Spring Batch, I will explain how to write the records read, to multiple files instead of one. We take the help of MultiResourceItemWriter, it writes to multiple file and suffixes the output fileNames with an index. For example if the file name to be created, is DemoData.txt and two files are…… Continue reading Writting to multiple files using MultiResourceItemWriter