Apr 23rd, 2012, 07:36 AM
FlatFileReader - set resource with wildcards?
I am totally new to Spring Batch. Someone helped me get a working framework going. We are reading flatfiles with a job and then writing them to an oracle database. I am using Eclipse as my IDE, the project is very simple. I have a Dto for every table in my db and a FieldSetMapper for every Dto. I have a seperate xml file configuring every job. The job has only a reader and writer and I run this with a maven command.
Example of maven command:
mvn clean compile exec:java -Dexec.mainClass=org.springframework.batch.core.lau nch.support.CommandLineJobRunner -Dexec.args="spring-batch-dataextracts-reward-balance-data.xml SpringJobBean.RewardBalanceDataJob"
Everything works perfectly. But my FlatFileItemReader takes in a constant filename at the moment. My filenames will always have the last part the same, but the beginning has a date_stamp and some other generated numbers. So ideally I want to pick up the file in the directory that looks like this: *_REW_BAL.txt.
<beansroperty name="resource" value="file:\DataExtractSampleFiles\20120422_10008016_122140_ REW_BAL.txt"/>
<!-- TODO : REPLACE FILE NAME -->
<beansroperty name="linesToSkip" value="1"/>
How do I do this? I have tried to read through the docs, but a nice example would help. And I assume I have to create new java classes if I need to send something in and extend one of the Spring Batch framework classes - like the commandrunner I use in my maven command?
Apr 24th, 2012, 06:40 AM
Apr 24th, 2012, 07:52 AM
Thanks. I implemented it, but still get errors that there is no resource to read (unless I put the full filename in - then it works). Am I just using the MultiResourceItemReader incorrectly?
This is my code snippet
<beans:bean id="MultiResourceItemReader.MemberRegistration" class="org.springframework.batch.item.file.MultiRe sourceItemReader">
<beans:property name="resources" value="file:D:\DataExtractSampleFiles\*MEM_REG.txt "/>
<beans:property name="delegate" ref="ItemReader.MemberRegistration">
<beans:bean id="ItemReader.MemberRegistration" class="org.springframework.batch.item.file.FlatFil eItemReader">
<beans:bean class="org.springframework.batch.item.file.mapping .DefaultLineMapper">
<beans:bean class="org.springframework.batch.item.file.transfo rm.DelimitedLineTokenizer">
<beans:property name="delimiter" value="|"/>
<beans:property name="names" value="memberId,loginName,email,registrationDate,l astAccessedDate,cobrandId,country,state,city,zipCo de,ipAddress,guid,extractDate,extractDateMilliseco nds"/>
<beans:bean class="za.com.MemRegFieldSetMapper" />
Apr 25th, 2012, 03:24 AM
This has been resolved. Some more reading and just had to change the back slash ("\") to forward slash ("/"). Thanks for all the help. Works perfectly now.
Tags for this Thread