I'm sorry in advance, I cannot give a lot of information about the batch affected by the error.
I would like to know generally what can cause an error on initializing a reader, when the XML input file is in the right repo. Are there any changes between spring batch v1 and spring batch v2 when initializing the reader process of a common simple step?
We operated a migration of the batch to spring batch V2 a few days ago.
ERROR org.springframework.batch.core.step.AbstractStep [] Encountered an error executing the step org.springframework.batch.item.ItemStreamException: Failed to initialize the reader at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:142) at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:96) at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:306) at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:192) at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:137) at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64) at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60) at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:152) at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:131) at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135) at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:301) at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:134) at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49) at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:127) at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:351) at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:577) Caused by: java.lang.IllegalStateException: Input resource must exist (reader is in 'strict' mode) at org.springframework.batch.item.xml.StaxEventItemReader.doOpen(StaxEventItemReader.java:187) at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:139) ... 15 more
Caused by: java.lang.IllegalStateException: Input resource must exist (reader is in 'strict' mode is self-explanatory, resource is missing and setting 'strict' mode will cause the error
If you are sure resource is in the right place check if you are using the right syntax to identify your resource path (file:, classpath:, url: or the others supported by Spring)?
Set the property strict to false in the org.springframework.batch.item.xml.StaxEventItemReader bean like so:
<property name="strict" value="false" />
This will log the path that Spring is trying to find (which is very useful for debugging this kind of error):
WARN: StaxEventItemReader.doOpen() - Input resource does not exist class path resource [path-to-resource]
However, strict=false will result in the StaxEventItemReader not throwing an exception anymore (so you might want to change the StaxEventItemReader back to strict=true afterwards).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With