0
votes

I created a batch job using spring batch framework, but if the reader return null, the batch job will create an empty file. Anyway to skip to next step and don't create the file.

<batch:job id="MY_BATCH_JOB">
    <batch:step id="step1" next="step2">
        <batch:tasklet>
            <batch:chunk reader="itemReader" writer="itemWriter"
                processor="itemProcessor" commit-interval="2">
            </batch:chunk>
            <batch:listeners>
                <batch:listener ref="readListener" />
            </batch:listeners>
        </batch:tasklet>
    </batch:step>
    <batch:step id="step2">
        <batch:tasklet>
            <batch:chunk reader="itemReader2" writer="itemWriter2"
                processor="itemProcessor2" commit-interval="2">
            </batch:chunk>
        </batch:tasklet>
    </batch:step>
</batch:job>
1

1 Answers

0
votes

If your ItemWriter is a FlatFileItemWriter, you can set the property shouldDeleteIfEmpty to true so that it doesn't create the file if it is empty.

<bean class="org.springframework.batch.item.file.FlatFileItemWriter">
    <property name="shouldDeleteIfEmpty" value="true"></property>
</bean>

If your ItemWriter is a custom item writer, then you can apply your own logic to not create the file.

Either way, it will go to next Step.