问题描述
我正在尝试使用java-config配置Spring批量流,
此流程基本上必须这样做:
I'm trying to configure a Flow in spring batch using java-config,this flow basically has to do this:
-
执行init步骤(在数据库中添加记录),
Execute a init step(which adds a record in the database),
然后执行决策程序以检查文件是否存在,
then execute a decider to check file existence,
2.1。如果文件存在,它将执行加载作业(这是一个并行的一堆步骤的另一个流程)
2.1. IF the files exists it will execute the load job (which is another flow with a bunch of steps in parallel)
- 执行完成步骤(在数据库中添加记录),这应该始终运行,即使2.1未执行。
I尝试进行此配置,但完成步骤永远不会运行:
I tried to do this configuration, but the finish step never runs:
Flow flow = new FlowBuilder<SimpleFlow>("commonFlow")
.start(stepBuilderFactory.get("initStep").tasklet(initTasklet).build())
.next(decider)
.on(FlowExecutionStatus.COMPLETED.getName())
.to(splitFlow)
.from(decider).on("*")
.end()
.next(stepBuilderFactory.get("finishStep").tasklet(finishTasklet).build())
.end();
我能够按照以下方式工作,但它根本不优雅:
I'm able to make it work doing as below, but it is not elegant at all:
Step finishStep = stepBuilderFactory.get("finishStep").tasklet(finishTasklet).build();
Flow flow = new FlowBuilder<SimpleFlow>("commonFlow")
.start(stepBuilderFactory.get("initStep").tasklet(initTasklet).build())
.next(decider)
.on(FlowExecutionStatus.COMPLETED.getName())
.to(splitFlow)
.next(finishStep)
.from(decider).on("*")
.to(finishStep)
.end();
有人知道在使用java-config做出决定后执行步骤的正确方法是什么? / p>
Does anybody know how is the right way to execute a step after a decision using java-config?
推荐答案
听起来这比实际需要的要复杂得多。您无需配置流程或决策程序。这是一个非常简单的进出工作。
It sounds like this is being made MUCH more complicated than it needs to be. You do not need to configure a flow or decider. This is a VERY simple in and out job.
最简单的选择是使用Spring Integration来检测文件的呈现并触发作业。
The simplest option is to use Spring Integration to detect the presents of a file and trigger the job.
下一个最简单的选项就是对文件进行石英或CRON作业检查并启动批处理作业。
The next simplest option is just to have a quartz or CRON job check for the file and start the batch job.
最后但并非最不重要的是,你可以让作业运行,如果ItemReader找不到文件,只需吞下例外。或者设置一个FileItemReader Listener来检查方法之前的文件。
Last but not least you can have the job run and if the ItemReader can not find the file(s) just swallow the exception. Or set a FileItemReader Listener to check for files on it's before method.
这篇关于在jobExeuctionDecider之后执行Spring Batch(java-config)步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!