春季批处理:我可以根据大小写入多个文件 [英] Spring Batch: Can i write to multiple files based on Size

查看:80
本文介绍了春季批处理:我可以根据大小写入多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在从事Spring Batch Job,我们需要根据大小写入多个文件.例如,我们需要写入输出文件output1.txt,一旦达到文件大小的5 mb,则必须将其写入output2.txt. 请建议

Spring批处理中是否有任何OOTB功能可以实现该功能,或者我们需要编写自定义代码来实现此功能

解决方案

Spring批处理项目编写器,尤其是FlatFileItemWriter并不像您需要的那样支持MaxFileSize属性,实际上,检查大小不是编写器的工作. >

我建议 1-)为一个文件实现您的编写器,并在第一步中输出output.txt. 2-)实施第二步作为Tasklet,将output.txt作为输入并将该文件拆分为所需的文件大小.

通过这种方式,您可以将文件拆分逻辑与主要步骤分开.

We are working on a Spring Batch Job, where we need to write to multiple files based on the size. For Example, we need to write to the output file output1.txt, once we reach 5 mb of the file size then it has to write into output2.txt. Please suggest

Is there any OOTB feature in Spring batch where we can achieve it or do we need to write custom code to achieve this

解决方案

Spring batch Item writers and especially FlatFileItemWriter's do not support a MaxFileSize property like you need and in fact it is not the job of writer to check the size.

I would suggest 1-) Implement your writer for one file and output output.txt in the first step. 2-) Implement a second step as a tasklet which takes output.txt as input and splits this file for the requested file size.

This way you will separate your file splitting logic from your main step.

这篇关于春季批处理:我可以根据大小写入多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆