Announcement Announcement Module
Collapse
No announcement yet.
Resource Not found for FlatFileItemReader Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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 :

    Code:
    org.springframework.batch.core.UnexpectedJobExecutionException: Failed to initialize the step
    	at 
    ...
    Caused by: org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
    	at 
    ...
    Caused by: java.lang.IllegalStateException: Resource must exist: [class path resource [theFile.csv]]
    at 
    ...
    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
    Mehdi
    Last edited by emile.coue; Mar 11th, 2009, 10: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.

    Comment


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

      Thank you.

      Comment


      • #4
        Hello

        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 :
        Code:
        	<bean name="retryPolicy" class="org.springframework.batch.retry.policy.SimpleRetryPolicy" >
        		<property name="maxAttempts"  value="2" />
        		<property name="retryableExceptionClasses" >
        			<list>
        				<value>java.lang.Exception</value>
        				<value>org.springframework.batch.core.step.skip.SkipLimitExceededException</value>
        				<value>org.springframework.batch.item.ReaderNotOpenException</value>
        				<value>org.springframework.batch.item.ItemStreamException</value>
        			</list>
        		</property>
        	</bean>
        	<bean name="backOffPolicy" class="org.springframework.batch.retry.backoff.FixedBackOffPolicy" >
        		<property name="backOffPeriod" value="5000" />
        	</bean>
        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 !

        Comment


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

          Comment


          • #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?)

            Comment


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

              Comment


              • #8
                thanks Dave for your prompt answers.

                I will try to implement a decider

                Comment

                Working...
                X