Spring Batch Item Reader - use skippedLinesCallback to set input field names -
i have simple job below:
<batch:step id="step"> <batch:tasklet> <batch:chunk reader="itemreader" processor="itemprocessor" writer="itemwriter" commit-interval="5000" /> </batch:tasklet> </batch:step>
itemreader below:
<bean id="itemreader" class="org.springframework.batch.item.file.flatfileitemreader" scope="step"> <property name="linestoskip" value="1"></property> <property name="skippedlinescallback" ref="skippedlinescallback" ></property> <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" value="${input_file_fields}" /> </bean> </property> <property name="fieldsetmapper"> <bean class="org.springframework.batch.item.file.mapping.passthroughfieldsetmapper" /> </property> </bean> </property> <property name="resource" value="#{stepexecutioncontext['inputkeyname']}" /> </bean>
i getting input files single line header. want set header line ${input_file_fields} reader. trying achieve using skippedlinescallback property got stucked in process.
is there anyway can read header line , set input_fields reader parse rest of records in file. please suggest.
you can:
- declare delimitedlinetokenizer bean not anonymous (call linetokenizer)
- in skippedlinescallback set linetokenizer reference property
- in skippedlinecallback: split header set names in linetokenizer ref setted before
Comments
Post a Comment