I have the following code
@Bean
public JdbcBatchItemWriter<QuotationDto> writer1() {
return new JdbcBatchItemWriterBuilder<QuotationDto>()
.itemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<>())
.sql("INSERT INTO ...")
.dataSource(dataSource)
.build();
}
@Bean
public JdbcBatchItemWriter<QuotationDto> writer2() {
return new JdbcBatchItemWriterBuilder<QuotationDto>()
.itemSqlParameterSourceProvider(new BeanPropertyItemSqlParameterSourceProvider<>())
.sql("INSERT INTO ...")
.dataSource(dataSource)
.build();
}
@Bean
public CompositeItemWriter<QuotationDto> compositeItemWriter() {
CompositeItemWriter writer = new CompositeItemWriter();
writer.setDelegates(Arrays.asList(writer1(), writer2()));
return writer;
}
@Bean
public Step step1() {
return stepBuilderFactory.get("step1")
.<QuotationDto, QuotationDto>chunk(5)
.reader(reader())
.processor(processor())
.writer(compositeItemWriter())
.stream(writer1())
.stream(writer2())
.build();
}
I get IntelliJ error in setting writer1 as stream, because id does no implement ItemStream.
What am I doing wrong? Do anyone has solutions? I don't find so much informations about java-based composite writer configuration.
JdbcBatchItemWriter
does not implementItemStream
so it cannot be used as a stream in a chunk-oriented step.If you want to compose two JDBC item writers, you can create a custom item writer that delegates to a
JdbcTemplate
. Here is a quick example: