Java 初始化阅读器在春季批次中的一个步骤失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19861131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Init reader fail on a step in spring batch
提问by Hubert Solecki
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?
我想知道当 XML 输入文件位于正确的存储库中时,什么会导致初始化读取器出错。spring batch v1和spring batch v2在初始化一个普通简单步骤的reader进程时有什么变化吗?
We operated a migration of the batch to spring batch V2 a few days ago.
几天前,我们将批次迁移到 Spring Batch V2。
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
错误 org.springframework.batch.core.step.AbstractStep [] 执行步骤 org.springframework.batch.item.ItemStreamException 时遇到错误:无法在 org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open( AbstractItemCountingItemStreamItemReader.java:142) 在 org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:96) 在 org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:306)在 org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:192) 在 org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:137) 在 org.springframework.batch.core .job.flow.JobFlowExecutor。executeStep(JobFlowExecutor.java:64) 在 org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60) 在 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) 在 org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:301) 在 org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java :134) 在 org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:49) 在 org.springframework.batch.core.launch.support。SimpleJobLauncher.run(SimpleJobLauncher.java:127) 在 org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:351) 在 org.springframework.batch.core.launch.support.CommandLineJobRunner.main( CommandLineJobRunner.java:577) 引起:java.lang.IllegalStateException:在 org.springframework.batch.item.xml.StaxEventItemReader.doOpen(StaxEventItemReader.java:187) 处必须存在输入资源(阅读器处于“严格”模式) org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:139) ... 15 更多java:351) 在 org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:577) 引起:java.lang.IllegalStateException:输入资源必须存在(阅读器处于“严格”模式)在org.springframework.batch.item.xml.StaxEventItemReader.doOpen(StaxEventItemReader.java:187) 在 org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:139) ... 15 更多java:351) 在 org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:577) 引起:java.lang.IllegalStateException:输入资源必须存在(阅读器处于“严格”模式)在org.springframework.batch.item.xml.StaxEventItemReader.doOpen(StaxEventItemReader.java:187) 在 org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:139) ... 15 更多doOpen(StaxEventItemReader.java:187) 在 org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:139) ... 15 更多doOpen(StaxEventItemReader.java:187) 在 org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:139) ... 15 更多
采纳答案by Luca Basso Ricci
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)?
Caused by: java.lang.IllegalStateException: Input resource must exist (reader is in 'strict' mode
不言自明,资源丢失,设置“严格”模式将导致错误
如果您确定资源位于正确的位置,请检查您是否使用正确的语法来识别您的资源路径(文件:,类路径:,网址:或 Spring 支持的其他人)?
回答by Hector Jimenez
Set the property strict to false in the org.springframework.batch.item.xml.StaxEventItemReader bean like so:
在 org.springframework.batch.item.xml.StaxEventItemReader bean 中将属性 strict 设置为 false,如下所示:
<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):
这将记录 Spring 尝试查找的路径(这对于调试此类错误非常有用):
WARN: StaxEventItemReader.doOpen() - Input resource does not exist class path resource [path-to-resource]
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).
但是,strict=false 将导致 StaxEventItemReader 不再抛出异常(因此您可能希望之后将 StaxEventItemReader 改回 strict=true)。