Announcement Announcement Module
No announcement yet.
Spring Batch Validation Framework - Looking for good Patterns Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Batch Validation Framework - Looking for good Patterns


    I am reading data from CSV flat file using FlatFileItemReader and want to validate the input records and if any errors, I just want to log it and still continue with the other records in the file. Having said that, what would be the good pattern to include the validation layer.

    1) Include validation (custom) layer in InputFeedFieldSetMapper while reading the input from flat file and log the invalid records

    	<bean name="feedMapper" class=""/>
    <bean name="feedLineMapper" class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
             <property name="fieldSetMapper" ref="feedMapper" />
             <property name="lineTokenizer" ref="feedLineTokenizer" />
    2) Include validation in Processing layer as shown below and use Errors.rejectValue etc. to log it in log file but I don't want to reject and just want to log it (no idea how to do it and more over if I use CompositeItemProcessor pattern, the subsequent processors won't be called if any Errors out of ValidatingItemProcessor)

    	<bean id="feedValidator" class="" />
        <bean id="validator" class="org.springframework.batch.item.validator.SpringValidator">
    	  <property name="validator" ref="feedValidator" />
    			<bean id="validateFileLoadProcessor" class="org.springframework.batch.item.validator.ValidatingItemProcessor">
    			  <property name="validator" ref="validator" />	  
    Please help me with this. Thanks.

  • #2
    When you say you don't want to "reject" it, just log it, what do you mean? Do you still want it to go through the processors and be written? If that's the case, using option 2 would be your best bet. In your Validator implementation, just log the failing item and don't throw the ValidationException.