Announcement Announcement Module
No announcement yet.
Resource Not found for FlatFileItemReader Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Resource Not found for FlatFileItemReader

    Hi Guys,

    I'm using a FlatFileItemReader to read my csv file. If it does not find the file it throws the exception :

    org.springframework.batch.core.UnexpectedJobExecutionException: Failed to initialize the step
    Caused by: org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
    Caused by: java.lang.IllegalStateException: Resource must exist: [class path resource [theFile.csv]]
    And the batch stops.

    Can I change this behavior?

    So, I want to save an exit status in the ExecutionContext and pass to next step.

    I'm using Spring batch 1.1.

    Thank you
    Last edited by emile.coue; Mar 11th, 2009, 09:08 AM.

  • #2
    Which version of 1.1? I think we changed that behavior in 1.1.3 or 1.1.4, I forget which.


    • #3
      I'm using the 1.1.0.RELEASE version.

      Thank you.


      • #4

        I'm using version 2.0 in which the FlatFileItemReader warns and the job continues if the file is not found.

        I would like to do the opposite scenario :
        How to prevent the job to continue and to make retry possible ?

        I already have a retryPolicy that works; I have tested with an incorrect file and the following retry/backoff Policies :
        	<bean name="retryPolicy" class="org.springframework.batch.retry.policy.SimpleRetryPolicy" >
        		<property name="maxAttempts"  value="2" />
        		<property name="retryableExceptionClasses" >
        	<bean name="backOffPolicy" class="org.springframework.batch.retry.backoff.FixedBackOffPolicy" >
        		<property name="backOffPeriod" value="5000" />
        I tried to throw an exception (ReaderNotOpenException) in a custom reader if the file is not found but in that case the job fails without applying the retry policy.

        Please help welcomed !


        • #5
          The retry policy only applies to items being processed, not the resources themselves being opened, so I'm not sure what you want to achieve.

          Did you see the "strict" flag on the FlatFileItemReader? (Actually the default has changed, so it should fail fast without you having to set it if you get the latest 2.0 release.)


          • #6
            I have searched this kind of flag. It's good to know it's available in the later versions.

            But if I understood you, it won't help me to retry the step if the file is not found ...

            Can you advise me for another stragety to achieve it ? (listener? decider?)


            • #7
              I suppose a decider would work, or a backoff step (in either case just wait and loop back to the step you want to retry).


              • #8
                thanks Dave for your prompt answers.

                I will try to implement a decider