2
 2015-11-24 15:56:32,512 [main] ERROR org.springframework.batch.core.step.AbstractStep:229[execute] - Encountered an error executing step multiThreadedStep in job extractJob
 java.lang.IllegalStateException: No resources to read. Set strict=false if this is not an error condition.
    at org.springframework.batch.item.file.MultiResourceItemReader.open(MultiResourceItemReader.java:173) ~[spring-batch-infrastructure-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:96) ~[spring-batch-infrastructure-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:310) ~[spring-batch-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:197) ~[spring-batch-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) [spring-batch-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:392) [spring-batch-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:135) [spring-batch-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306) [spring-batch-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135) [spring-batch-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) [spring-core-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128) [spring-batch-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_60]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_60]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_60]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_60]
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) [spring-aop-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) [spring-aop-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) [spring-aop-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127) [spring-batch-core-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) [spring-aop-4.1.6.RELEASE.jar:4.1.6.RELEASE]
    at com.sun.proxy.$Proxy33.run(Unknown Source) [na:na]
Tunaki
  • 132,869
  • 46
  • 340
  • 423
  • Please provide more info, it's unclear what you're asking. – Diogo Rocha Nov 24 '15 at 10:37
  • We are having result set in which we have 100 records. now we have created a parrelel batch application to process it in which we have given grid size of 4. now 4 file will be created in which we are having 25 records each. When we are trying to merge those 4 file into a single file then it is throwing an exception and it is working using xml but throwing an exception using annotation.somehow resources are set when it is loading first time but 4 files are creating after first step but since it is loaded initially that time there was no file in that directory that is now causing the problem.and – Madhav Mishra Nov 24 '15 at 10:44
  • it is throwing an exception java.lang.IllegalStateException: No resources to read. Set strict=false if this is not an error condition. – Madhav Mishra Nov 24 '15 at 10:45
  • Please post the code that generates the error so we can help you – Phate01 Nov 24 '15 at 10:47
  • @Phate01 Value("${param.flatFilePathRead}") private Resource[] resources; Bean BeforeStep public MultiResourceItemReader multithreadedItemReaderExtractJob() { MultiResourceItemReader fr = new MultiResourceItemReader<>(); fr.setResources(resources); fr.setStrict(true); fr.setDelegate((ResourceAwareItemReaderItemStream extends String>) multithreadItemReader()); return fr; } – Madhav Mishra Nov 24 '15 at 11:01
  • Please see if this can help: http://stackoverflow.com/questions/27333440/how-to-ensure-all-step-partitions-are-finished-before-going-into-the-next-job-st – Phate01 Nov 24 '15 at 11:09

2 Answers2

2

The actual error of your StackTrace is : java.lang.IllegalStateException: No resources to read.

This means that your reader property resource is either not set or the expression doesn't match any file.

Here's an example configuration :

<bean id="multiResourceReader" class="org.springframework.batch.item.file.MultiResourceItemReader">
    <property name="resources" value="file:folder/*.csv" />
    <property name="delegate" ref="delegate" />
</bean>

In this configuration you can see the resource property has been set to file:folder/*.csv. This means your exception will be thrown if there are no files matching this expression, i.e. no CSV files in the folder.

So what you have to do here is check your bean configuration and check for the presence of actual files in the filesystem.

Thrax
  • 1,926
  • 1
  • 17
  • 32
1

Check whether the reader's scope has been defined as "step", e.g

<bean id="multiResourceReader"
    class=" org.springframework.batch.item.file.MultiResourceItemReader" scope="step">
    <property name="resources" value="file:C://files/*" />
    <property name="delegate" ref="flatFileItemReader" />
</bean>

This means that the properties will be resolved at run time instead of at initialization. I hope this helps you and anyone else that may need it.

theeGwandaru
  • 400
  • 2
  • 14