I have a reader which is reading data from a flat file. I would like to modify this list of items(to see for duplicates) before they are passed to the writer. I tried using ItemWriteListener but it does not return the list, the return type of beforeWrite() method is void. The whole list is not available to me in reader or processor, so I cannot do any manipulation there. So, how do I actually modify this list before writer is called?
Asked
Active
Viewed 415 times
1 Answers
0
you can use ItemWriteListener<Item>
and save your items in a @Bean List<Items>
like this:
@Component
public class `MyItemWriterListener implements ItemWriteListener<MyItem> {
@Autowired
final List<MyItems> listMyItems;
@Override
public void beforeWrite(List<MyItem> items) throws Exception {
//what I want to do before my Writer method
listMyItems.addAll(...)
}
...
and get your updated List of Items in the writer :
public class MyItemWriter implements ItemWriter<Item> {
@Autowired
final List<MyItems> listMyItems;
void write(List<Item> items) {
//save listMyItems
}
}
Or you can promote your data on a JobExecutionContext
like explainedhere

Achraf Elo.
- 305
- 3
- 11