Multiple itemwriters in Spring batch

后端 未结 5 656
伪装坚强ぢ
伪装坚强ぢ 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:33

    You don't necessarily have to use xml like the example. If the rest of your code uses annotation, you could simply do the following.

    public ItemWriter writerOne(){
        ItemWriter writer = new ItemWriter();
        //your logic here
        return writer;
    }
    
    public ItemWriter writerTwo(){
        ItemWriter writer = new ItemWriter();
        //your logic here
        return writer;
    }
    
    public CompositeItemWriter compositeItemWriter(){
        CompositeItemWriter writer = new CompositeItemWriter();
        writer.setDelegates(Arrays.asList(writerOne(),writerTwo()));
        return writer;
    }
    

提交回复
热议问题