Anand
Anand

Reputation: 21320

FlatFileItemWriter generating blank file on exception in Spring batch

I am working on spring batch job that does the conventional READ > PROCESS > WRITE file operation.

Below is the sample code of writer i am using.

<bean id="simBeqResponseFlatFileWriter" class="org.springframework.batch.item.file.FlatFileItemWriter">
        <property name="resource" ref="fileWriteSystemResource"></property>
        <property name="lineAggregator">
            <bean class="org.springframework.batch.item.file.transform.PassThroughLineAggregator" />
        </property>
    </bean>

I am facing a issue where even on some exception thrown in the code, a blank file is getting generated.On any exception being thrown in the code, the file should not be generated at all.

Need some help in resolving the issue.

Upvotes: 0

Views: 2067

Answers (1)

Anand
Anand

Reputation: 21320

I found the solution. There is a property of FaltFileItemWriter which needs to be used as follows

<property name="shouldDeleteIfEmpty" value="true"/>

Upvotes: 3

Related Questions