Without seeing you in the configuration of ItemReader, I cannot be sure, but if you use something like FlatFileItemReader for parsing csv, if in strict mode it will check the number of columns.
Assuming the reader looks like this:
<bean id="iItemReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step"> <property name="linesToSkip" value="1"/> <property name="comments" value="#" /> <property name="encoding" value="UTF-8"/> <property name="lineMapper" > <bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper"> <property name="lineTokenizer"> <bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer"> <property name="delimiter" value=","/> <property name="names"> <list > <value>First_Field</value> <value>Second_Field</value> </list> </property> <property name="strict" value="true"/> </bean> </property> <property name="fieldSetMapper"> <bean class="uk.co.package.FieldSetMapper"> <property name="dateFormat" value="yyyy-MM-dd HH:mm:ss"/> </bean> </property> </bean> </property> </bean>
It will throw a FlatFileParseException exception for any rows that cannot be handled. This includes the line number and can be processed in the listener.
source share