gpt4 book ai didi

spring-batch - 无法将类型 'java.util.Collections$UnmodifiableMap' 的属性值转换为所需类型 'org.springframework.batch.item.ExecutionContext'

转载 作者:行者123 更新时间:2023-12-05 06:39:14 43 4
gpt4 key购买 nike

当我尝试使用 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;
}

错误的堆栈跟踪是:

SEVERE: Encountered an error executing step stepCandidatos in job XXXBatch org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.Candidatos_itemProcessor' defined in class path resource [spring/batch/jobs/jobXXX.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.util.Collections$UnmodifiableMap' to required type 'org.springframework.batch.item.ExecutionContext' for property 'stepContext'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.util.Collections$UnmodifiableMap] to required type [org.springframework.batch.item.ExecutionContext] for property 'stepContext': no matching editors or conversion strategy found at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) at org.springframework.beans.factory.support.AbstractBeanFactory$2.getObject(AbstractBeanFactory.java:343) at org.springframework.batch.core.scope.StepScope.get(StepScope.java:113) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:338) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:187) at com.sun.proxy.$Proxy23.process(Unknown Source) at org.springframework.batch.core.step.item.SimpleChunkProcessor.doProcess(SimpleChunkProcessor.java:126) at org.springframework.batch.core.step.item.SimpleChunkProcessor.transform(SimpleChunkProcessor.java:293) at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:192) at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:75) at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406) at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330) at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133) at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:271) at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:81) at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374) at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144) at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257) at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200) at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) 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:67) at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169) at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144) at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:134) at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306) at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135) at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128) at com.XXX.Test.run(Test.java:32) at com.XXX.Test.main(Test.java:15) Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.util.Collections$UnmodifiableMap' to required type 'org.springframework.batch.item.ExecutionContext' for property 'stepContext'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.util.Collections$UnmodifiableMap] to required type [org.springframework.batch.item.ExecutionContext] for property 'stepContext': no matching editors or conversion strategy found at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:474) at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:511) at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:505) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1502) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1461) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ... 34 more Caused by: java.lang.IllegalStateException: Cannot convert value of type [java.util.Collections$UnmodifiableMap] to required type [org.springframework.batch.item.ExecutionContext] for property 'stepContext': no matching editors or conversion strategy found at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:267) at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:459) ... 40 more jun 28, 2017 9:54:31 AM org.springframework.batch.core.launch.support.SimpleJobLauncher run INFO: Job: [FlowJob: [name=CertSeurBatch]] completed with the following parameters: [{}] and the following status: [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>

关于spring-batch - 无法将类型 'java.util.Collections$UnmodifiableMap' 的属性值转换为所需类型 'org.springframework.batch.item.ExecutionContext',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44797496/

43 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com