In this post of Spring Batch, I will explain how to add chunk level listeners. In Spring Batch, items are read one at a time, but written to file as a chunk (a collection of records written as one unit). So if total records are 100 and chunk size is 50, they will be two…… Continue reading Adding Chunk Level Listeners using ChunkListener
Category: XML
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
Filtering items using ItemProcessor
In Spring Batch, items are read from the source using reader and written to destination using a writer. Sometimes, we need to add business logic between the reader and writer for the following purpose1) Filtering an item2) Converting an item read from one format to another before written to the destination3) Modify the item read…… Continue reading Filtering items using ItemProcessor
Adding job level listeners using JobExecutionListener
Spring Batch provides a facility to add listeners at job level. The listeners are executed before the job is started and after the job is finished. This post explains how to create listeners and integrate them with the job. We can add our custom processing logic in these listeners and expect them to be called…… Continue reading Adding job level listeners using JobExecutionListener
FlatFileHeaderCallback and FlatFileFooterCallback example
In this post I will explain how to add header and footer to the destination file created by Spring batch. When Spring batch transfer records from source to destination file in batch, it provides facility through which the programmer can provide header and footer information thathas to added in the destination file. To take advantage…… Continue reading FlatFileHeaderCallback and FlatFileFooterCallback example
Custom FieldSetMapper example
In the previous post “Spring Batch Simple Example” we used “BeanWrapperFieldSetMapper” while reading the employee records from the file. The BeanWrapperFieldSetMapper created a newinstance of Employee class for every employee record in the file and set the instance fields. We can have more control on the task performed by BeanWrapperFieldSetMapper by providing a custom implementation…… Continue reading Custom FieldSetMapper example
Spring Batch Simple Example Part 3
In this post I will explain how to combine the reader and writer in a job and how to run the job. We define a job which will transfer the employee records from one file to another file in batches. <batch:job id=”importEmployees”> <batch:step id=”readWriteEmployees”> <batch:tasklet> <batch:chunk reader=”reader” writer=”writer” commit-interval=”50″/> </batch:tasklet> </batch:step> </batch:job> <bean id=”transactionManager” class=”org.springframework.jdbc.datasource.DataSourceTransactionManager”>…… Continue reading Spring Batch Simple Example Part 3
Spring Batch Simple Example Part 2
In this post, I will explain how to write the employee objects created in the reading process to a file. To write the list of employee records in batches, we need to create an instance of org.springframework.batch.item.file.FlatFileItemWriter. It takes two information1) the resource file where the information has to be written2) An instance of LineAggregator…… Continue reading Spring Batch Simple Example Part 2