-1

I am new to Spring Batch, and trying to read data from FlatFile and writing the valid record into the database and invalid record into cvs file. I used ClassifierCompositeItemWriter for writing into multiple FlatFile. It was working fine, but the same was not working while trying to write in DB and FlatFile at the same time. Please give me some suggestion.

ferpel
  • 206
  • 3
  • 12

1 Answers1

0

I would not use a ClassifierCompositeItemWriter for that use case, instead, it is more natural to use a SkipListener for invalid data.

In your example, you can use a regular item writer to write valid data to the database, and register a skip listener that would write invalid items to a file.

You can implement the skip logic in an item processor for example. This processor would check if the current item is valid: It it is valid, let it go to the writer, otherwise throw a skippable exception.

Hope this helps.

Mahmoud Ben Hassine
  • 28,519
  • 3
  • 32
  • 50