问题描述
我有一个Spring Batch作业,需要做以下工作:
我已经使用了下面的
- A MultiResourceItemReader 读取文件并委托给 FlatFileItemReader
- FlatFileItemReader 使用 LineMapper em>, FieldSetMapper
- ItemProcessor 操作数据读取 写入数据库
我想要做什么
$ b
-
- 根据执行状态将每个文件重命名为步骤结束时的PROCESSED / ERROR 如何传递 FlatFileItemReade的资源文件名r 处理到 StepExecutionListener ?
- 如何将资源文件名传递给 ItemProcessor 保存读取数据的文件的名称
下面是我的相关配置
< batch:job id =myJobjob-repository =jobRepository>
< batch:step id =processFiles>
< batch:tasklet>
< batch:chunk reader =multiResourceReaderprocessor =myItemProcessorwriter =myItemWritercommit-interval =100/>
< / batch:tasklet>
< batch:listeners>
< batch:listener ref =myStepListener/>
< / batch:listeners>
< / batch:job>
这种情况类似于 I have a Spring Batch job that needs to do the below I have used the below What I want to do Below is my relevant config This scenario is similar to this one. 这篇关于Spring批处理 - 从MultiResourceItemReader传递资源名称> FlatFileItemReader到StepExecutionListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
我更喜欢解决方案#2:海事组织的成功/错误条件很容易检查,步骤流程更清晰,分离。
请考虑,我希望我的建议能够帮到你。 <batch:job id="myJob" job-repository="jobRepository">
<batch:step id="processFiles">
<batch:tasklet>
<batch:chunk reader="multiResourceReader" processor="myItemProcessor" writer="myItemWriter" commit-interval="100" />
</batch:tasklet>
<batch:listeners>
<batch:listener ref="myStepListener"/>
</batch:listeners>
</batch:step>
</batch:job>
I'm not a fan of first solution because is too messy and file rename is "hidden" into java code and can't be easily detected from job's xml definition.
I prefer solution #2: IMO success/error conditions are easy to check and step flow is more cleaner and well separated.
Get your consideration, I hope my advices will help.