I am supposed to read from multiple files and then write into a single file after applying some processing and transforming logic. In order to do so, I have created a single batch job with 3 steps, where the 1st and 2nd steps are responsible for reading the data and writing in an intermediary temporary file, and finally in the 3rd or the last step I am trying to read that temporary file and apply the final logic to create the end file.
The error I am getting is:
- Always the intermediate temporary file is getting created successfully as an end result of step 1 and step 2, but step 3 fails to create the final file.
- Step 3 is able to find and read from that file and also was successful in preparing the data, but the file is never getting created.
- Spring Batch is throwing a MojoException, and it is hard to find the actual cause.
- For testing, if I keep the temporary file pre-created and directly run the last step, then the final file gets created successfully. But when all the steps are running and this temporary file is created on the fly, only then this error occurs.
- I have tried with
start-next
steps and also withflow
, i.e.,start
-on(COMPLTED)
-to
-end
approach, but every time, the same results. - Finally, I have made
transactional
asfalse
andforceSync
astrue
in the writer but with no luck.
下面是作者的幻灯片和工作:
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();
没有人能够就此提供一些见解或建议?