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:

  1. declare delimitedlinetokenizer bean not anonymous (call linetokenizer)
  2. in skippedlinescallback set linetokenizer reference property
  3. in skippedlinecallback: split header set names in linetokenizer ref setted before

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -