spring-batch - Spring Batch:需要更好的作业配置
问题描述
我的 Spring 批处理应用程序处理 5 种不同类型的文件中的 1 种。所有 5 种类型的流程完全相同。我的配置相当长而且笨重。有人可以通过重用流程来帮助我压缩它吗?
这是我能想到的最好的:
return jobBuilderFactory.get(CommonConstants.BATCH_JOB_DISTRIBUTION)
.listener(jobListener)
.start(retrieveFileStep())
.next(createFileJobDetailStep(fileJobDetailTasklet))
.next(fileTypeDecider)
.from(fileTypeDecider).on(FileType.YearEnd.name()).to(yearEndStep)
.from(yearEndStep).on("ERROR").to(moveFileToErrorStep(fileOperationsTasklet))
.from(yearEndStep).on("SUCCESS").to(moveFileToProcessedStep(fileOperationsTasklet))
.from(fileTypeDecider).on(FileType.Quarterly.name()).to(quarterlyStep)
.from(quarterlyStep).on("ERROR").to(moveFileToErrorStep(fileOperationsTasklet))
.from(quarterlyStep).on("SUCCESS").to(moveFileToProcessedStep(fileOperationsTasklet))
//[repeat 3 more times...]
我想要一个更好的方式来写这个。谢谢。
解决方案
我最终创建了一个子流程,并在整个作业配置中重用了该子流程。
public Flow flow(String flowName, Step step, Tasklet fileOperationsTasklet) {
return new FlowBuilder<Flow>(flowName)
.start(step)
.from(step).on("ERROR").to(moveFileToErrorStep(fileOperationsTasklet))
.from(step).on("SUCCESS").to(moveFileToProcessedStep(fileOperationsTasklet))
.end();
}
所以现在我的配置包括:
.from(fileTypeDecider).on(FileType.YearEnd.name()).to(flow("yearEndFlow", yearEndStep, fileOperationsTasklet))
推荐阅读
- r - 使用 rollRegres 中的 roll_regres 时出错:“宽度”上的断言失败
- elasticsearch - ElasticSearch - 按文档列值提升
- vue.js - 访问网络主机域不是ip
- c# - 控制器导致招摇的内部错误
- html - 工具提示仅在悬停时不显示
- android - 使用许可字符串在 ExoPlayer 上播放受 Widevine DRM 保护的内容
- css - 在重新加载页面 css 样式时被丢弃
- reactjs - mui datatable 获取复选框选择的行数据
- deep-learning - 一次又一次地运行深度学习模型以获得更好的结果可以吗?
- symfony - Sylius Grid,如何按实体中不存在的属性排序