How to custom Spring Batch DelimitedLineTokenizer -
i have 2 file types insert in database.
format : aa;bb;cc , aa;bb;cc;dd;ee
this flatfileitemreader :
<bean name="readercontracttoaddintoprv" class="org.springframework.batch.item.file.flatfileitemreader"> <property name="comments" value="#" /> <property name="linestoskip" value="1" /> <property name="strict" value="false" /> <property name="linemapper"> <bean class="org.springframework.batch.item.file.mapping.defaultlinemapper"> <property name="fieldsetmapper"> <bean class="net.wl.batchs.fieldsetmapper.linetocreateintoprvfieldsetmapper" /> </property> <property name="linetokenizer"> <bean class="org.springframework.batch.item.file.transform.delimitedlinetokenizer"> <property name="delimiter" value=";"/> <property name="names" value="aa,bb,cc,dd,ee" /> </bean> </property> </bean> </property> </bean>
i want setup works both types of files.
for moment, have :
org.springframework.batch.item.file.transform.incorrecttokencountexception: incorrect number of tokens found in record: expected 3 actual 5
do have ideas?
thank you.
edit : after correction :
<bean name="readercontracttoaddintoprv" class="org.springframework.batch.item.file.flatfileitemreader"> <property name="comments" value="#" /> <property name="linestoskip" value="1" /> <property name="strict" value="false" /> <property name="linemapper"> <bean class="org.springframework.batch.item.file.mapping.defaultlinemapper" p:linetokenizer-ref="multilinefiletokenizer"> <property name="fieldsetmapper"> <bean class="net.wl.batchs.fieldsetmapper.linetocreateintoprvfieldsetmapper" /> </property> </bean> </property> </bean> <bean id="multilinefiletokenizer" class="org.springframework.batch.item.file.transform.patternmatchingcompositelinetokenizer"> <property name="tokenizers"> <map> <entry key="*;*;*;*;*" value-ref="nsce_iccid_msisdn_login_pwd"/> <entry key="*;*;*" value-ref="nsce_iccid_msisdn"/> <entry key="*" value-ref="headerdefault"/> </map> </property> </bean> <bean id="parentlinetokenizer" class="org.springframework.batch.item.file.transform.delimitedlinetokenizer" abstract="true"> <property name="delimiter" value=";"/> </bean> <bean id="nsce_iccid_msisdn_login_pwd" parent="parentlinetokenizer"> <property name="names" value="nsce,iccid,msisdn,login,pwd" /> </bean> <bean id="nsce_iccid_msisdn" parent="parentlinetokenizer"> <property name="names" value="nsce,iccid,msisdn" /> </bean> <bean id="headerdefault" parent="parentlinetokenizer"> <property name="names" value="nsce,iccid,msisdn" /> </bean>
the issue isn't tokenizer. you'll have use patternmatchingcompositelinemapper
(http://docs.spring.io/spring-batch/trunk/apidocs/org/springframework/batch/item/file/mapping/patternmatchingcompositelinemapper.html). allow create pattern each line type have , associate appropriate linetokenizer
.
you can see linemapper
in action in our samples here: https://github.com/spring-projects/spring-batch/blob/master/spring-batch-samples/src/main/resources/jobs/multilineorderinputtokenizers.xml
Comments
Post a Comment