I am writing a spring batch application where my processor returns List, as long as return type is list,
@Bean(destroyMethod = "")
@StepScope
public ItemWriterAdapter<List<MyType>> myWriterAdapter()
{
ItemWriterAdapter<List<MyType>> writer = new ItemWriterAdapter<>();
writer.setTargetObject(myWriter(null));
writer.setTargetMethod("write");
return writer;
}
i keep getting this exception:
org.springframework.batch.item.WriterNotOpenException: Writer must be open before it can be written to at org.springframework.batch.item.file.FlatFileItemWriter.write(FlatFileItemWriter.java:270)
Writer code:
@Bean
@StepScope
public FlatFileItemWriter< MyType> monetateWriter(@Value(STEP_EC_LOCAL_FILE_PATH) String localFilePath)
{
final FlatFileItemWriter<MyType> writer = new FlatFileItemWriter<>();
writer.setResource(getLocalFile(localFilePath));
writer.setHeaderCallback(new MyHeaderCallback());
writer.setAppendAllowed(true);
writer.setLineAggregator(new DelimitedLineAggregator<MyType>() {
{
setDelimiter(COMMA_DELIMITER);
setFieldExtractor(new BeanWrapperFieldExtractor<MyType>() {
{
setNames(new String[] {"id", "title"});
}
});
}
});
return writer;
}
>` which is for a list. Who is going to wrap your items in a `List`? You should not be expecting this to be done automatically by the adapter, that's why I'm saying I see no added value of this adapter. You either need to encapsulate the output type of your processor in an aggregate like `class Items { private List list; }`, or use something like https://stackoverflow.com/questions/24004959/return-multiple-items-from-spring-batch-itemprocessor