Spring Batch skip exception for ItemWriter -
i'm trying use spring batch 2.2.5 java config. here config have:
@configuration @enablebatchprocessing public class jobconfiguration { @autowired private jobbuilderfactory jobbuilder; @autowired private stepbuilderfactory stepbuilder; @bean @autowired public job processdocumentsjob() { return jobbuilder.get("processdocumentsjob") .start(procesingstep()) .build(); } @bean @autowired public step procesingstep() { compositeitemprocessor<file, documentpackagefilemetadata> compositeprocessor = new compositeitemprocessor<file, documentpackagefilemetadata>(); compositeprocessor.setdelegates(lists.newarraylist( documentpackagefilevalidationprocessor(), documentmetadatafiletransformer() )); return stepbuilder.get("procesingstep") .<file, documentpackagefilemetadata>chunk(1) .reader(documentpackagefilereader()) .processor(compositeprocessor) .writer(documentmetadatafilemigrator()) .faulttolerant() .skip(documentimportexception.class) .skiplimit(10) .listener(stepexecutionlistener()) .build(); } .... }
with config above, if itemwriter (the bean pointed documentmetadatafilemigrator) throws 'documentimportexception', exception wont skipped. spring batch retry same input again. i.e. use same input against 'documentpackagefilevalidationprocessor'.
but, if move logic inside itemwriter itemprocessor:
@bean @autowired public step procesingstep() { compositeitemprocessor<file, documentpackagefilemetadata> compositeprocessor = new compositeitemprocessor<file, documentpackagefilemetadata>(); compositeprocessor.setdelegates(lists.newarraylist( documentpackagefilevalidationprocessor(), documentmetadatafiletransformer(), documentmetadatafilemigratorasprocessor() // same itemwriter, implemented itemprocessor )); return stepbuilder.get("procesingstep") .<file, documentpackagefilemetadata>chunk(1) .reader(documentpackagefilereader()) .processor(compositeprocessor) .faulttolerant() .skip(documentimportexception.class) .skiplimit(10) .listener(stepexecutionlistener()) .build(); }
then exception skipped correctly. i.e. spring batch not retry same item against 'documentpackagefilevalidationprocessor'. go next item process (the 1 returned 'documentpackagefilereader').
is bug on spring batch, or behaving expected? if so, can point me relevant documentation?
thanks guys, , apology if fundamental question.
best regards,
alex
that behavior correct. itemwriter receives list of items write. if skippable exception thrown, spring batch attempts determine item caused exception item skipped. way done transaction rolled back, commit interval changed 1, , each item reprocessed , write attempted again. allows item error skipped instead of needing skip entire chunk.
this same issue discussed here (only using xml config): how skipping implemented in spring batch?
Comments
Post a Comment