开发者

way to pin point failed item in a chunk during write in spring batch

What are the ways to log exact item which failed during writing a chunk of say 10 items size ?

Is there a way to catch it in onWriteError method of ItemWriteListener ? Is it possible to know this by extending 开发者_运维问答ItemWriter interface ?

Thanks and Regards, Nik


you could configure skip logic with Integer.MAX_VALUE = 2.147.483.647

<step id="step1">
   <tasklet>
      <chunk reader="flatFileItemReader" writer="itemWriter" 
             commit-interval="10" skip-limit="2147483647">
         <skippable-exception-classes>
            <include class="org.springframework.batch.item.file.FlatFileParseException"/>
         </skippable-exception-classes>
      </chunk>
   </tasklet>
   <listeners>
        <listener ref="customSkipListener" />
   </listeners>
</step>

and use a skip listener (see the annotations there too) to log bad items during writing

if your writer is already a custom implementation, it could be extended to be a Listener which responds to OnSkipInWrite only, just add method with @OnSkipInWrite and register the writer as listener (*)

(*) beware - if the writer is a stream too, do not register as listener, streams are automatically registered as (step)listeners

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜