Search code examples
filespring-batchreaderwriter

Spring Batch MultiResourceItemReader count records per file


I'm using MultiResourceItemReader to read all files under a folder by PathMatchingResourcePatternResolver, and all records of every file will be written into a table (a table of detail records), and I also have to keep count of records in per file into another table (a table of main records).

How to get count of records per file? I tried to use listener, but I only got total count of all read files.

Could anyone give me some hints?

combination of using readers, writers or listeners provided by Spring Batch

or what kind of custom readers, writers or listeners I should do ?


Solution

  • The goal of the MultiResourceItemReader is to read a set of resources as if they were a single resource. There is no callback that allows you to inject code before or after jumping from one resource to another.

    What you can do is make your items implement ResourceAware and count them in an item processor.