Announcement Announcement Module
No announcement yet.
Newbie question about items processing Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Newbie question about items processing

    Hi !

    I would like to thank you guys for the amazing job you have done with Spring Batch. I only started working with it yesterday but it seems pretty neat.

    I have a pretty basic question about skipping items that fail to be processed (wether it is when they are read or written). I have a step with a flatFileItemReader that reads text files and a FlatFileItemWriter that writes in a file. So far so good.

    I have a few listeners that implement ItemReadListener and StepExecutionListener. My problem is that when a line fails to be parsed (invalid number of tokens) then I see in my log the output from the onReadError() method from my ItemReaderListener class but then there is an error message from AbstractStep class and then the StepExecutionListener.

    How can I do to make the step just ignore the failed lines ? I want them to be logged in a specific external file using probably the onReadError() method and not show this AbstractStep error message and then process the next line ? Right now the error propagates from the ItemReader to the job and the job dies.

    Below is the code from my job configuration file and then the output from my log file. I think it is pretty trivial but I do not see how (yet)

    Thanks for any help !

    <bean id="transactionManager" class="" />
    <bean id="lineTokenizer" class="test.implementation.MyDelimitedLineTokenizer" />
    <bean id="fieldSetMapper" class="test.implementation.MyFieldSetMapper" />
    <!-- LISTENERS -->
    <bean id="itemReaderListener" class="test.implementation.MyItemReaderListener" />
    <bean id="itemWriterListener" class="test.implementation.MyItemWriterListener" />
    <bean id="stepListener" class="test.implementation.MyStepListener" />
    <!--  FILE PROCESSING -->
    <bean id="flatFileItemReader" class="test.implementation.AuditLogFlatFileItemReader" >
    	<property name="resource" value="file:C:/DATA/INBOX/test.txt"></property>
    	<property name="lineTokenizer" ref="lineTokenizer" />
    	<property name="fieldSetMapper" ref="fieldSetMapper" />
        <!--  STEPS -->
    <bean id="firstStep" class="org.springframework.batch.core.step.item.SimpleStepFactoryBean">
    	<property name="transactionManager" ref="transactionManager" />
    	<property name="jobRepository" ref="jobRepository" />
    	<property name="commitInterval" value="2" />
    	<property name="itemReader" ref="flatFileItemReader" />
    	<property name="itemWriter" ref="logItemWriter" />
    	<property name="listeners">
    			<ref bean="itemReaderListener" />
    			<ref bean="itemWriterListener" />
    			<ref bean="stepListener" />
    <!--  JOBS -->
    <bean id="simpleJob" class="test.job.AuditLogLoader">
    	<property name="name" value="simpleJob" />
    	<property name="steps">
    			<ref local="firstStep" />
    	<property name="jobRepository" ref="jobRepository" />
    	<property name="restartable" value="true" />
    [java] 15:03:51,333  WARN MyItemReaderListener:58 - -------------- About to read a line --------------
    [java] 15:03:51,333 ERROR MyItemReaderListener:36 - Failed to read line: Parsing error at line: 1
    [java] 15:03:51,333 ERROR MyItemReaderListener:37 - Will log it in error file here.
    [java] 15:03:51,349 ERROR AbstractStep:195 - Encountered an error executing the step: class org.springframework.batch.item.file.FlatFileParseException: Parsing error
    [java] 15:03:51,349  WARN MyStepListener:59 - Step generated an error: continuable=true;exitCode=CONTINUABLE;exitDescription=

  • #2
    What version of spring batch are you using?

    You need to use a different Step factory bean. In 1.x it's called SkipLimitStepFactoryBean and in 2.0 it's called FaultTolerantStepFactoryBean. Using these, you can configure the skippableExceptionClasses property to indicate which exception types should be skipped.


    • #3
      I will do that. Thanks a bunch !