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 item or creating a completely new object. In the second case, the written item…… 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,0 EMP_ID1,EMP_NAME1,EMP_STATUS1,1 EMP_ID2,EMP_NAME2,EMP_STATUS2,2 EMP_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…… 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

Passing Job Parameters 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)…… 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 package12; 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 item 2) writing of an items 3) 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…… Continue reading ItemReadListener, ItemWriteListener, and ItemProcessListener Example