- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建一个作业来处理上一步保存的文件。
作业定义如下:
<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/
我的 Spring Batch 作业读取包含两种类型 header 的 csv 文件列表。如果文件头与两种可能的头类型之一不匹配,我希望读者跳过整个文件。 我查看了Spring Boot batch
我有一个包含大约 100 万个文件的 tar.gz 存档。我想使用 spring-batch 中的 MultiResourceItemReader 来读取这些文件。 问题:MultiResourceI
我有一个使用 spring 任务调度和批处理作业的 java 应用程序。我依靠 job 中的 MultiResourceItemReader 从目录中读取一些文件、处理它们并删除这些文件。外部进程负责
我正在尝试创建一个作业来处理上一步保存的文件。 作业定义如下:
我正在尝试创建一个作业来处理上一步保存的文件。 作业定义如下:
我有一个 Spring 批处理操作,其中有要读取的源 file1、file2 和 file3 并希望写入 fileA、fileB 和 fileC 如下所示: file1->fileA file2->f
我在 Spring Batch 中使用 MultiResourceItemReader 读取多个 XML 文件,我想获取当前资源。这是我的配置: public class MultiFileResou
有没有办法让MultiResourceItemReader处理的currentResource在beforeStep方法中可用。请给我一个>工作代码示例。 我尝试将 multiresourceread
除了从 JobParameters 获取值或使用 Value 标签之外,还有其他方法可以自定义 MultiResourceItemReader 资源吗?我尝试了以下方法,但没有成功。
你好,Java 向导, 我在进入 Spring 批处理时遇到了很多麻烦。现在开门见山。我需要处理一个文件夹中的所有文件(xmls),然后它们将它们写回,并添加少量内容。问题是我想保留输入文件名。我对此
Spring Batch有一个方便的MultiResourceItemReader ,我在 Java EE 7 Batch Processing API 中找不到类似的类(class)。我想知道 Ja
我正在使用 spring-batch 多资源 JsonItemReader从如下位置读取多个文件: public MultiResourceItemReader getReader() { Re
我想配置 spring-batch 以顺序读取特定文件夹内的所有 csv 文件。 以下不起作用,因为代理将尝试打开一个名为 *.csv 的文件,这当然是无效的。我需要在这里改变什么? @Bea
在批处理服务中,我使用 MultiResourceItemReader 读取多个 XML 文件,该文件委托(delegate)给 StaxEventItemReader。 如果读取文件时发生错误(例如
在 Spring 批处理应用程序中,我们如何在处理每个文件时将文件从 BatchFileDir 文件夹移动到目标文件夹。 BatchFileDir 文件夹中会有一堆文件,所以我正在使用 MultiRe
我有一个 MultiResourceItemReader,其中有一个自定义 ItemReader 作为委托(delegate)。我面临的问题是,当我启 Action 业时,会一遍又一遍地读取同一个文件
我是一名优秀的程序员,十分优秀!