-
Apr 23rd, 2012, 07:36 AM
#1
FlatFileReader - set resource with wildcards?
Hi guys,
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.
<beans:bean id="ItemReader.RewardBalanceDataJob"
class="org.springframework.batch.item.file.FlatFil eItemReader">
<beans
roperty name="resource" value="file
:\DataExtractSampleFiles\20120422_10008016_122140_ REW_BAL.txt"/>
<!-- TODO : REPLACE FILE NAME -->
<beans
roperty 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?
Thanks
-
Apr 24th, 2012, 06:40 AM
#2
-
Apr 24th, 2012, 07:52 AM
#3
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:property>
</beans:bean>
<beans:bean id="ItemReader.MemberRegistration" class="org.springframework.batch.item.file.FlatFil eItemReader">
<beans:property name="lineMapper">
<beans:bean class="org.springframework.batch.item.file.mapping .DefaultLineMapper">
<beans:property name="lineTokenizer">
<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>
</beans:property>
<beans:property name="fieldSetMapper">
<beans:bean class="za.com.MemRegFieldSetMapper" />
</beans:property>
</beans:bean>
</beans:property>
</beans:bean>
-
Apr 25th, 2012, 03:24 AM
#4
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules