Results 1 to 8 of 8

Thread: Resource Not found for FlatFileItemReader

  1. #1
    Join Date
    Mar 2009
    Posts
    2

    Default 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 at 09:08 AM.

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

    Default

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

  3. #3
    Join Date
    Mar 2009
    Posts
    2

    Default

    I'm using the 1.1.0.RELEASE version.

    Thank you.

  4. #4
    Join Date
    Mar 2009
    Posts
    8

    Default

    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 !

  5. #5
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    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. #6
    Join Date
    Mar 2009
    Posts
    8

    Default

    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. #7
    Join Date
    Jun 2005
    Posts
    4,241

    Default

    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. #8
    Join Date
    Mar 2009
    Posts
    8

    Default

    thanks Dave for your prompt answers.

    I will try to implement a decider

Posting Permissions

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