user1019072
user1019072

Reputation: 299

Spring Batch File Writer Exception handling

I have a Spring Batch process which has following kind of code.

<step id="step1" xmlns="http://www.springframework.org/schema/batch">
        <tasklet allow-start-if-complete="true">
            <chunk reader="reader1" writer="writer1" commit-interval="10"/>
        </tasklet>
    </step>

<bean id="writer1" class="org.springframework.batch.item.file.FlatFileItemWriter">
    <property name="resource" ref="resourceFlatFile" />   
    <property name="shouldDeleteIfExists" value="true" />
    <property name="transactional" value="true" />
    <property name = "lineAggregator"> 
        <bean class="org.springframework.batch.item.file.transform.DelimitedLineAggregator" >
            <property name="delimiter" value=""/>
            <property name ="fieldExtractor"> 
                <bean class="com.path.MyExtractor" />
            </property>  
        </bean>
    </property> 
</bean> 

Basically my reader gives set of records from database. My writer (writer1) writes it to a flat file. If there is any problem in writing a record to the file, I would like to mark that record status as failed in database. So how to handle these kind of scenarios? Any help is appreciated.

Thanks My question is if I get any kind of exception

Upvotes: 3

Views: 6870

Answers (1)

Joshua Moore
Joshua Moore

Reputation: 24776

I would recommend you look into using a ItemWriteListener and update the status of the failed records in the onWriteError implementation.

Upvotes: 2

Related Questions