简体   繁体   中英

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM