英文:
Issue in AsyncItemWriter with Spring Batch 5
问题
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 the 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.
英文:
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
答案1
得分: 1
你可能有版本不匹配的问题。Spring Boot 3 使用了 Spring Batch 5。在 Spring Batch 5 中,ItemWriter 接口的方法从 write(List<? extends T> items)
更改为 write(Chunk<? extends T> chunk)
。
然而,AsyncItemWriter 位于 Spring Batch Integration 中。我猜测你正在使用 Spring Batch Integration 4,它仍然实现了旧的 ItemWriter 接口,导致运行时异常。升级到 Spring Batch Integration 5 应该解决此问题。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论