简体   繁体   中英

How should I write a results file using Spring Batch

I have a Spring Batch import process that has the following steps:

  1. Read a file in a specific format
  2. Save data for people, attributes and appointments (each file line can mean multiple inserts to multiple tables)
  3. Write results file (primarily result of the read, but sometimes we can't process the read data into something we can coherently insert)

I currently have #1 in a set of Readers (one for each file format), and #2 and #3 in single Writer class. I feel that writing the results file should be a separate step from writing the data to the database, but I am not sure how to do this.

The options I know of are:

  1. A step listener
  2. A tasklet (?)

Are there other options and which option would be the way Spring Batch is designed for?

You can separate the current ItemWriter you have into two ItemWriter s and use a CompositeItemWriter as your chunk writer. This will delegate in the order you specify to the your two writers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM