Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java.lang.IllegalStateException: ItemWriter must be provided after updating spring batch to 4.1.1

Previously, we were using Spring Batch 3.0.6 and tried to update it to 4.1.1. I have a job with only an ItemReader and an ItemProcessor - no ItermWriter provided. It was working fine before update.

Now, I am getting:

java.lang.IllegalStateException: ItemWriter must be provided.

What is changed from previous version?

    <job id="myJob" parent="baseJob">
        <step id="myStep" parent="baseStep">
            <tasklet>
                <chunk reader="myItemReader" processor="myProcessor"
                       commit-interval="1" skip-limit="100000" retry-limit="1">
                    <skippable-exception-classes>
                        <include class="ExceptionClass"/>
                    </skippable-exception-classes>
                    <retryable-exception-classes>
                        <include class="ExceptionClass"/>
                    </retryable-exception-classes>
                </chunk>
            </tasklet>
            <listeners merge="true">
                <listener ref="promotionListener"/>
                <listener ref="skippableExceptionListener"/>
            </listeners>
        </step>
    </job>
like image 973
Jyo Avatar asked Dec 18 '19 15:12

Jyo


People also ask

What is ItemWriter in Spring Batch?

ItemWriter. It is the element of the step of a batch process which writes data. An ItemWriter writes one item a time. Spring Batch provides an Interface ItemWriter. All the writers implement this interface.

What is ItemWriter in Java?

ItemWriter defines the batch artifact that writes to a list of items for chunk processing.

Which is the correct implementation of ItemWriter interface?

FlatFileItemWriter is the ItemWriter implementation provided to generate text file output. Similar to FlatFileItemReader in many respects, this class addresses the issues with file-based output in Java with a clean, consistent interface for you to use.


1 Answers

ItemWriter become mandatory in BATCH-2624. Based on the information from the issue link , this change takes effect after version 3.0.10 , 4.0.2 and 4.1.0

If you really do not need an ItemWriter , you can implement a dummy one:

public class NoOpItemWriter implements  ItemWriter<Object>{

  @Override
  public void write(List<? extends Object> items) throws Exception {
  }
}

And configure to use it:

<bean id="noOpItemWriter" class="org.foo.bar.NoOpItemWriter"/>

<chunk reader="myItemReader" processor="myProcessor" writer="noOpItemWriter">
    .....           
</chunk>
like image 175
Ken Chan Avatar answered Sep 17 '22 15:09

Ken Chan