我应该从多个文件中读取,然后在应用一些处理和转换逻辑后写入单个文件。 为此,我创建了一个包含 3 个步骤的批处理作业,其中第 1 步和第 2 步负责读取数据并写入中间临时文件,最后在第 3 步或最后一步中,我尝试读取该临时文件并应用最终逻辑来创建最终文件。
我收到的错误是:
start-next
步骤以及flow
,即start
-on(COMPLTED)
-to
-end
方法,但每次都是相同的结果。transactional
制作为false
和forceSync
制作为true
,但没有运气。以下是作者和工作的片段:
new FlatFileOutputWriter(
new FlatFileItemWriterBuilder<MyPOJO>()
.name("lastFileWriter")
.resource(new FileSystemResource("<THE PATH TO THE TEMPORARY FILE, THAT WAS CRATD IN THE PREVIOUS STEP>"))
.shouldDeleteIfEmpty(true)
.lineAggregator(
(item) -> item.id() + fieldDelimeter + item.value())
.append(false)
.transactional(false)
.forceSync(true)
.build()
)
以下是工作片段:
return new JobBuilder("myJob", jobRepository)
.listener(jobCompletionListener)
.start(step1)
.on("COMPLETD").to(step2)
.on("COMPLETD").to(step3)
.end()
.build();
有人可以对此提供一些见解或建议吗?
我找到了一种替代方法来完成要求。这是我使用的逻辑-
H2 DB
H2 DB
的表中读取数据并写入最终文件中next()
来应用顺序流,而不是 from()
、to()
和 on()
所以,片段应该看起来像这样 -
.start(step1, that will read the file and store in DB)
.next(step2, that will read another file and store in DB)
.next(step3, that will fetch the data from the DB and write in the file)
注: 如果数据从
DB
获取后直接写入文件,没有任何处理,那么不要使用任何处理器,即step
(最后一个)将只有一个reader
(从 DB
获取)和 writer
(写入文件)。