MkSM56852
MkSM56852

Reputation: 3

Spring Batch: one Reader and two different Writer

I am using SpringBatch to read an xml file and save it in a database and also in another file. The object I want to read has the structure OBJECT(name, logicalName, version , key , status). I want to save all attributes in the database and the name attribute in the file. For the moment I have created two different steps for this process:
Step 1 -> save to database Step 2 -> save name attribute to file

My question is how to run these two steps in parallel even if they read the same file? I tried to use the same ItemReader and a CompositeItemWriter in this case, saving to database is done successfully but all objects are also saved to the destination file and I want only the name attribute.

Upvotes: 0

Views: 503

Answers (1)

Mahmoud Ben Hassine
Mahmoud Ben Hassine

Reputation: 31710

The CompositeItemWriter is the way to go, no need for two steps for that. You would need to write a custom FieldSetExtractor that extracts only the attribute you want to write in the file.

Upvotes: 1

Related Questions