Search code examples
javaspring-batchbatch-processing

Spring Batch Split Processor


I need to apply different processor chains based on record properties, producing different record types.

                             /--> processor A --> writer A
reader --> split processor --|
                             \--> processor B --> writer B

So that processing vary by read items:

A record (read) -> (split processor) -> (processor A) -> (writer A)
B record (read) -> (split processor) -> (processor B) -> (writer B)

This can be made using multiple ItemProcessListeners and writing filtering logic in afterProcess().

Looking for a better approach.


Solution

  • The ClassifierCompositeItemProcessor is what you are looking for (what you call split processor). This item processor uses a Classifier to classify items and pass them to delegate processors accordingly.

    To achieve the pattern you described, you would need to combine this processor with a similar item writer: the ClassifierCompositeItemWriter.