Announcement Announcement Module
Collapse
No announcement yet.
FlatFileReader - set resource with wildcards? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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">
    <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?

    Thanks

  • #2
    Use the MultiResourceItemReader
    http://static.springsource.org/sprin...multiFileInput

    Comment


    • #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">
      <beansroperty name="resources" value="file:\DataExtractSampleFiles\*MEM_REG.txt"/>
      <beansroperty name="delegate" ref="ItemReader.MemberRegistration">
      </beansroperty>
      </beans:bean>

      <beans:bean id="ItemReader.MemberRegistration" class="org.springframework.batch.item.file.FlatFil eItemReader">
      <beansroperty name="lineMapper">
      <beans:bean class="org.springframework.batch.item.file.mapping .DefaultLineMapper">
      <beansroperty name="lineTokenizer">
      <beans:bean class="org.springframework.batch.item.file.transfo rm.DelimitedLineTokenizer">
      <beansroperty name="delimiter" value="|"/>
      <beansroperty name="names" value="memberId,loginName,email,registrationDate,l astAccessedDate,cobrandId,country,state,city,zipCo de,ipAddress,guid,extractDate,extractDateMilliseco nds"/>
      </beans:bean>
      </beansroperty>
      <beansroperty name="fieldSetMapper">
      <beans:bean class="za.com.MemRegFieldSetMapper" />
      </beansroperty>
      </beans:bean>
      </beansroperty>
      </beans:bean>

      Comment


      • #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.

        Comment

        Working...
        X