gpt4 book ai didi

Spring-batch 在 MultiResourceItemReader 上失败

转载 作者:行者123 更新时间:2023-12-01 22:22:32 27 4
gpt4 key购买 nike

我正在尝试创建一个作业来处理上一步保存的文件。

作业定义如下:

<bean id="downloadCatalogTasklet" class="DownloadCatalogTasklet" scope="step" />

<bean id="customItemReader" class="CustomItemReader" scope="step"/>

<bean id="itemWriter" class="NoOpItemWriter" scope="step"/>

<bean id="multiResourceReader" class="org.springframework.batch.item.file.MultiResourceItemReader" scope="step">
<property name="strict" value="true" />
<property name="resources" value="file://C:/temp/unzipped/*.txt" />
<property name="delegate" ref="customItemReader" />
</bean>

<batch:job id="importCatalog">
<batch:step id="downloadCatalog">
<batch:tasklet ref="downloadCatalogTasklet" />
<batch:next on="COMPLETED" to="processCatalog" />
<batch:fail on="FAILED"/>
</batch:step>
<batch:step id="processCatalog">
<batch:tasklet>
<batch:chunk reader="multiResourceReader" writer="itemWriter" commit-interval="1" />
</batch:tasklet>
</batch:step>
</batch:job>

第一步工作正常。目录已正确下载并解压缩。但是,当 spring batch 尝试执行步骤 processCatalog 时,它会抛出以下错误(只是):

2016-08-23 09:45:31 ERROR AbstractStep:229 - Encountered an error executing step processCatalog in job importCatalog
java.lang.IllegalArgumentException: Name must be assigned for the sake of defining the execution context keys prefix.
at org.springframework.util.Assert.hasText(Assert.java:162)
at org.springframework.batch.item.util.ExecutionContextUserSupport.getKey(ExecutionContextUserSupport.java:59)
at org.springframework.batch.item.ItemStreamSupport.getExecutionContextKey(ItemStreamSupport.java:71)
at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.update(AbstractItemCountingItemStreamItemReader.java:183)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy7.update(Unknown Source)
at org.springframework.batch.item.file.MultiResourceItemReader.update(MultiResourceItemReader.java:209)

这是我第一次使用 MultiResourceItemReader。我不知道我是否遗漏了什么。我正在使用带有 java 1.7 的 spring-batch 3.0.7。

看来我应该为ExecutionContext 指定一个名称,但我不知道该怎么做。

最佳答案

您需要在配置中为您的 ItemReader 指定一个名称,以便 ExecutionContext 中的值可以作为前缀,因此每个阅读器都是唯一的。按如下方式配置您的阅读器,它们应该可以工作:

<bean id="multiResourceReader" class="org.springframework.batch.item.file.MultiResourceItemReader" scope="step">
<property name="name" value="myMultiResourceItemReader"/>
<property name="strict" value="true" />
<property name="resources" value="file://C:/temp/unzipped/*.txt" />
<property name="delegate" ref="customItemReader" />
</bean>

关于Spring-batch 在 MultiResourceItemReader 上失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39102755/

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