For a project I need to process items from one table and generate 3 different items for 3 different tables, all 3 in a second data source different from the one of the first
Your question is really two questions. Let's look at each individually:
Can an ItemProcessor
return multiple items
An ItemProcessor can only return one item at a time for each item that is passed in. Because of this, in your specific scenario, you'll need your ItemProcessor
to return a wrapper object that wraps items A, B, C, and D.
How can I write different types in the same step
Spring Batch relies heavily on composition in it's programming model. Since your ItemProcessor
will be returning a wrapper object, you'll end up writing an ItemWriter
that unwraps items A, B, C, and D and delegates the writing of each to the apropriate writer. So in the final solution, you'll end up with 5 ItemWriter
s: one for each item type and one that wraps all of those. Take a look at our CompositeItemWriter
as an example here: https://github.com/spring-projects/spring-batch/blob/master/spring-batch-infrastructure/src/main/java/org/springframework/batch/item/support/CompositeItemWriter.java