0

I have upgraded my spring boot version from 2.7.9 to 3.0.5 and facing some issues in implementing AsyncItemWriter.

Following is my code snippet:

@Bean
    public AsyncItemWriter<myDto> asyncWriter() {
        AsyncItemWriter<myDto> asyncItemWriter = new AsyncItemWriter<>();
        asyncItemWriter.setDelegate(eventMessageItemWriter());
        return asyncItemWriter;
    }

And the eventMessageItemWriter is defined as:

public class EventMessageItemWriter implements ItemWriter<myDto> {

    @Autowired
    private Myservice myservice;

    @Override
    public void write(Chunk<? extends myDto> chunk) throws Exception {
        for (myDto rqData : chunk) {
            myservice.insertRequestData(rqData);
        }
        
    }

And I am getting following error:

java.lang.AbstractMethodError: Receiver class org.springframework.batch.integration.async.AsyncItemWriter does not define or inherit an implementation of the resolved method 'abstract void write(org.springframework.batch.item.Chunk)' of interface org.springframework.batch.item.ItemWriter.

Can anyone please help. Thanks in advance

DevThiman
  • 920
  • 1
  • 9
  • 24

1 Answers1

1

You likely have a version mismatch. Spring Boot 3 uses Spring Batch 5. In Spring Batch 5, the ItemWriter interface was changed from write(List<? extends T> items) to write(Chunk<? extends T> chunk).

AsyncItemWriter however is in Spring Batch Integration. My guess is that you're using Spring Batch Integration 4, which still implements the old ItemWriter interface, causing a runtime exception. Upgrading to Spring Batch Integration 5 should fix this.

Christian S.
  • 877
  • 2
  • 9
  • 20
  • Any hint about performance? in my project, with this update the performance became morw slow than 1000% to write 2M of record from 6 minutes now need more than 1h – Davide Boldrin Jun 22 '23 at 10:16