Multiple itemwriters in Spring batch

后端 未结 5 624
伪装坚强ぢ
伪装坚强ぢ 2020-12-08 14:12

I am currently writing a Spring batch where I am reading a chunk of data, processing it and then I wish to pass this data to 2 writers. One writer would simply update the da

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-08 14:44

    Depending on your need, another option is to extend the Writer class and add functionality there. For example, I have a project where I am extending HibernateItemWriter and then overriding write(List items). I then send the objects I am writing along with my sessionFactory to the doWrite method of the Writer: doWrite(sessionFactory, filteredRecords).

    So in the example above, I could write to the csv file in my extended class and then the HibernateItemWriter would write to the database. Obviously this might not be ideal for this example, but for certain scenarios it is a nice option.

提交回复
热议问题