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

感情迁移 提交于 2021-01-28 03:53:10

问题


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


回答1:


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



来源:https://stackoverflow.com/questions/6772318/way-to-pin-point-failed-item-in-a-chunk-during-write-in-spring-batch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!