Search code examples
javaspringspring-batchspring-batch-tasklet

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>

Solution

  • 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>