Results 1 to 10 of 10

Thread: Dynamic file name for FileItemRead

  1. #1
    Join Date
    Jan 2007
    Posts
    14

    Default Dynamic file name for FileItemRead

    I am looking for a way to kick off a batch which has a filename as an input parameter.
    the filename would be used by the FileItemReader to open the file and process it.

    I have not found any good (for me) explanations about how to do it. I know that I should set the resource parameter of my file reader as follows:
    <property name="resource"value="/data/input/${file.name}" />
    but I still don't get how that works. Do I need to create a variable file.name in my parameter list?

    Thanks

    Xav

  2. #2
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    It's covered in Chapter 3 of the reference documentation:

    http://static.springframework.org/sp...e.html#d0e1694

    Please let me know if after reading the docs you are still having issues. We're always trying to improve them.

  3. #3
    Join Date
    Jan 2007
    Posts
    14

    Default

    Thanks.

    I see the doc has improved a lot recently.

    Xav

  4. #4

    Default

    Hello.

    The link is broken, and I couldn't find an explanation of how to use a batch parameter as a resource path (I end up using a custom laucher registering the
    parameter as a System property, combined with a PropertyPlaceholderConfigurer).

  5. #5
    Join Date
    Feb 2008
    Posts
    488

  6. #6

    Default

    Thank you.

    I already try that syntax :

    Code:
    <property name="resource" value="#{jobParameters[input.file.name]}" />
    But I must be missing something, the el expression is not interpreted and I end up with something like :

    Code:
    at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:207)
    	at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:254)
    Caused by: java.lang.IllegalStateException: Input resource must exist (reader is in 'strict' mode): class path resource [#{jobParameters[input.file.name]}]
    	at org.springframework.batch.item.file.FlatFileItemReader.doOpen(FlatFileItemReader.java:245)
    	at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:108)
    	... 18 more
    Maybe there's an additional configuration required to use this feature ?

  7. #7
    Join Date
    Feb 2008
    Posts
    488

    Default

    Make sure that your <bean/> has scope="step"

  8. #8

    Default

    It's working now, thank you very much !

    Here's the final config :

    Code:
    <bean id="theReader" class="org.springframework.batch.item.file.FlatFileItemReader">
            <property name="lineMapper">
                ...
            </property>        
            <property name="resource">
                <bean class="org.springframework.core.io.FileSystemResource" scope="step">
                    <constructor-arg value="#{jobParameters[inputfilename]}" />
                </bean>
            </property>
        </bean>

  9. #9

    Default

    It might be useful to add this tip in the reference documentation.

    Is there a process to submit a documentation update ?

  10. #10
    Join Date
    Feb 2008
    Posts
    488

    Default

    The subsequent section in the document is about StepScope, but I agree it might be nice to put a note so that readers are aware that the next section applies to them.

    All issues (including Documentation issues) should be logged in JIRA: http://jira.springframework.org/browse/BATCH

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •