当我尝试使用 StepExecutionContext 在步骤之间共享数据时,出现此错误。我对这个框架非常菜鸟,所以我希望这是一个简单的问题,但据我所知,它必须在框架上,因为我不在任何地方使用“UnmodifyingMap”。
如果有人遇到过这个问题,分享解决方案会很有帮助,提前致谢。
bean 的定义如下:
<bean id="Candidatos_itemProcessor" class="com.xxx.CandidatoProcessorTest" scope="step">
<property name="stepContext" value="#{stepExecutionContext}"/>
处理器的实现是:
public class CandidatoProcessorTest implements ItemProcessor<Candidato, Candidato> {
private ExecutionContext stepContext = null;
//other private xxx
public Candidato process(Candidato item) throws Exception {
//some logic here
stepContext.put("cod_situacion", cod_situacion);
stepContext.put("des_situacion", des_situacion);
stepContext.put("fec_situacion", fec_situacion);
//other logic
return item;
}
//a private aux method
public void setStepContext(ExecutionContext stepContext) {
this.stepContext = stepContext;
}
}
错误的堆栈跟踪是:
严重:在作业 XXXBatch 中执行步骤 stepCandidatos 时遇到错误
org.springframework.beans.factory.BeanCreationException:创建类路径资源[spring/batch/jobs/jobXXX.xml]中定义的名为“scopedTarget.Candidatos_itemProcessor”的bean时出错:bean初始化失败;嵌套异常是 org.springframework.beans.ConversionNotSupportedException:无法将属性“stepContext”的类型“java.util.Collections$UnmodifyingMap”的属性值转换为所需类型“org.springframework.batch.item.ExecutionContext”;嵌套异常是 java.lang.IllegalStateException:无法将属性“stepContext”的类型 [java.util.Collections$UnmodifyingMap] 的值转换为所需类型 [org.springframework.batch.item.ExecutionContext]:找不到匹配的编辑器或转换策略
在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
在 org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:343)
在 org.springframework.batch.core.scope.StepScope.get(StepScope.java:113)
在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:338)
在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
在 org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35)
在org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:187)
在 com.sun.proxy.$Proxy23.process(来源未知)
在 org.springframework.batch.core.step.item.SimpleChunkProcessor.doProcess(SimpleChunkProcessor.java:126)
在 org.springframework.batch.core.step.item.SimpleChunkProcessor.transform(SimpleChunkProcessor.java:293)
在 org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:192)
在 org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:75)
在 org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406)
在 org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330)
在 org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
在 org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:271)
在 org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:81)
在 org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374)
在 org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)
在 org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)
在 org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257)
在 org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200)
在 org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
在 org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)
在 org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
在 org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)
在 org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)
在 org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134)
在 org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306)
在 org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135)
在 org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
在 org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128)
在 com.XXX.Test.run(Test.java:32)
在 com.XXX.Test.main(Test.java:15)
引起:org.springframework.beans.ConversionNotSupportedException:无法将类型“java.util.Collections$UnmodifyingMap”的属性值转换为属性“stepContext”所需的类型“org.springframework.batch.item.ExecutionContext”;嵌套异常是 java.lang.IllegalStateException:无法将属性“stepContext”的类型 [java.util.Collections$UnmodifyingMap] 的值转换为所需类型 [org.springframework.batch.item.ExecutionContext]:找不到匹配的编辑器或转换策略
在org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:474)
在org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:511)
在org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:505)
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1502)
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1461)
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
在 org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
... 34 更多
原因:java.lang.IllegalStateException:无法将属性“stepContext”的类型 [java.util.Collections$UnmodifyingMap] 的值转换为所需类型 [org.springframework.batch.item.ExecutionContext]:找不到匹配的编辑器或转换策略
在org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:267)
在org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:459)
... 40 更多
2017 年 6 月 28 日上午 9:54:31 org.springframework.batch.core.launch.support.SimpleJobLauncher 运行
信息:作业:[FlowJob:[name=CertSeurBatch]] 已完成,具有以下参数:[{}] 和以下状态:[FAILED]
就我而言,问题是tasklet的配置是
@Bean
@StepScope
public MyTasklet createTasklet(@Value("#{jobExecutionContext}") ExecutionContext executionContext)
解决问题的方法是将其更改为
@Bean
@StepScope
public MyTasklet createTasklet(@Value("#{stepExecution.jobExecution.executionContext}") ExecutionContext executionContext)
这是一个迟到的答案,但希望它对将来的人有所帮助。
使用的 Spring 组件版本:
<springframework.version>5.2.12.RELEASE</springframework.version>
<spring-integration.version>5.3.4.RELEASE</spring-integration.version>
<spring-batch-admin.version>1.3.1.RELEASE</spring-batch-admin.version>
<spring-batch.version>4.2.5.RELEASE</spring-batch.version>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)