How to set the resource of MultiResourceItemWriter dynamically from ItemReader in Spring Batch

前端 未结 2 1687
生来不讨喜
生来不讨喜 2020-12-19 19:18

The batch job is:

  • Reading from a csv file

  • Create an xml file for every record(line) in the csv with name Patent.ID.xml(where ID is a field i

2条回答
  •  情话喂你
    2020-12-19 19:58

    I couldn't find a way to make Luca's solution to work, so I extended MultiResourceItemWriter this way:

    public class MyMultipleItemWriter extends MultiResourceItemWriter
    {
        @Override
        public void write(List items) throws Exception
        {
            this.setResourceSuffixCreator(new MySuffixCreator(items.get(0).getField()));
            super.write(items);
        }
    }
    

提交回复
热议问题