AsyncItemWriter 在 Spring Batch 5 中出现问题。

huangapple go评论64阅读模式
英文:

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&lt;myDto&gt; asyncWriter() {
		AsyncItemWriter&lt;myDto&gt; asyncItemWriter = new AsyncItemWriter&lt;&gt;();
		asyncItemWriter.setDelegate(eventMessageItemWriter());
		return asyncItemWriter;
	}

And the eventMessageItemWriter is defined as:

public class EventMessageItemWriter implements ItemWriter&lt;myDto&gt; {

	@Autowired
	private Myservice myservice;

	@Override
	public void write(Chunk&lt;? extends myDto&gt; 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&lt;? extends T&gt; items) 更改为 write(Chunk&lt;? extends T&gt; 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&lt;? extends T&gt; items) to write(Chunk&lt;? extends T&gt; 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.

huangapple
  • 本文由 发表于 2023年4月13日 21:10:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76005840.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定