当我尝试使用StepExecutionContext在步骤之间共享数据时,我收到此错误。我非常喜欢这个框架所以我希望这是一个简单的问题,但据我所知,它必须在框架上,因为我不使用" UnmodifiableMap"任何地方。
如果有人碰到这个问题,那么分享解决方案会有很大帮助,谢谢。
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:使用name&#39; scopedTarget.Candidatos_itemProcessor&#39;创建bean时出错。在类路径资源[spring / batch / jobs / jobXXX.xml]中定义:bean的初始化失败;嵌套异常是org.springframework.beans.ConversionNotSupportedException:无法转换类型&#39; java.util.Collections $ UnmodifiableMap&#39;的属性值。要求的类型&#39; org.springframework.batch.item.ExecutionContext&#39; for property&#39; stepContext&#39 ;;嵌套异常是java.lang.IllegalStateException:无法将类型[java.util.Collections $ UnmodifiableMap]的值转换为所需的类型[org.springframework.batch.item.ExecutionContext]以获取属性&#39; stepContext&#39;:无匹配编辑或转换策略找到 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547) 在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) at 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:无法转换类型&#39; java.util.Collections $ UnmodifiableMap&#39;的属性值要求的类型&#39; org.springframework.batch.item.ExecutionContext&#39; for property&#39; stepContext&#39 ;;嵌套异常是java.lang.IllegalStateException:无法将类型[java.util.Collections $ UnmodifiableMap]的值转换为所需的类型[org.springframework.batch.item.ExecutionContext]以获取属性&#39; stepContext&#39;:无匹配编辑或转换策略找到 在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:无法将类型[java.util.Collections $ UnmodifiableMap]的值转换为所需类型[org.springframework.batch.item.ExecutionContext]的属性&#39; stepContext&#39;:无匹配编辑或转换策略找到 在org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:267) 在org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:459) ......还有40多个 jun 28,2017 9:54:31 AM org.springframework.batch.core.launch.support.SimpleJobLauncher run 信息:作业:[FlowJob:[name = CertSeurBatch]]使用以下参数完成:[{}]和以下状态:[FAILED]
答案 0 :(得分:0)
就我而言,问题是 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>