I am using Spring Batch
in Spring Boot
application. The Spring Boot
version is 1.3.5.RELEASE
.
I am trying to use CompositeItemWriter
so that the list of items will first be compressed/zipped by WriterOne and then be passed to WriterTwo where they will be written in the database.
Here is my writer 1:
@Component
public class Writer1 implements org.springframework.batch.item.ItemWriter<SimpleObject> {
@Override
public void write(List<? extends SimpleObject> list) throws Exception {
for(SimpleObject simpleObject: list){
// code which compresses the file
}
}
}
Here is my writer 2:
@Component
public class Writer2 implements org.springframework.batch.item.ItemWriter<SimpleObject> {
@Override
public void write(List<? extends SimpleObject> list) throws Exception {
for(SimpleObject simpleObject: list){
// the file object meta data are being writtren to database.
}
}
}
Here is I am trying to initializing task-step and providing it a CompositeItemWriter instead of ItemWriter.
CompositeItemWriter compositeItemWriter = new CompositeItemWriter();
compositeItemWriter.setDelegates(Arrays.asList(writer1,writer2));
TaskletStep processingStep = stepBuilderFactory.get(getLabel() + "-" + UUID.randomUUID().toString())
.<SimpleObject, SimpleObject>chunk(5)
.reader(reader)
.processor(processor)
.writer(compositeItemWriter).transactionManager(txManager).build();
Then the code gives compile time error:
Error:(337, 83) java: cannot find symbol
symbol: method build()
location: class org.springframework.batch.core.step.builder.StepBuilderHelper
This below code worked in my case.
Here is my writer 1:
Here is my writer 2:
Here I am trying to initializing
Tasklet
and providing it aCompositeItemWriter
:Kindly let me know if I missed anything or had some incorrect information.