Home > Mobile >  Spring Batch: one Reader and two different Writer
Spring Batch: one Reader and two different Writer

Time:04-26

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.

CodePudding user response:

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.

  • Related