问题
I'm trying to port a spring-batch job, which is defined in xml to a java-config based job. This is a snippet of my job-configuration-file:
<decision id="decision" decider="someDecider">
<next on="continue" to="stepCont" />
<next on="timeout" to="stepTimeout" />
<end on="COMPLETED" />
</decision>
<step id="stepCont" next="stepReport">
... do something
</step>
<step id="stepReport" next="decision">
... create report
</step>
<step id="stepTimeout">
...
</step>
Is there a way to create such a loop with spring-java-config?
I started:
.get("myJob")
.start(someStepBefore())
.next(someDecider).on("timeout").to(stepTimeout())
.from(someDecider).on("continue").to(stepCont())
.from(someDecider).on("COMPLETED").end().build()
.build();
It must be like:
.get("myJob")
.start(someStepBefore())
.next(someDecider).on("timeout").to(stepTimeout())
.from(someDecider).on("continue").to(stepCont()).next(someDecider)...
.from(someDecider).on("COMPLETED").end().build()
.build();
My job is like the loopFlowSample. How could I realize it without xml?
回答1:
How about this :
FlowBuilder<Flow> flowBuilder = new FlowBuilder<Flow>("flow1");
Flow flow = flowBuilder
.start(importPersonStep)
.next(loopDecider)
.on("CONTINUE")
.to(importPersonStep)
.from(loopDecider)
.on("COMPLETED")
.end()
.build();
return jobs.get("importUserJob")
.incrementer(new RunIdIncrementer())
.start(flow)
.end()
.build();
回答2:
I know really late but I didn't find a correct example and this question kept coming up in my google searches.
Here's a working example with the latest spring batch.
return jobs.get("myJob")
.start(someStepBefore)
.next(stepReport)
.next(someDecider).on("timeout").to(stepTimeout)
.from(someDecider).on("continue").to(stepCont)
.from(someDecider).on("COMPLETED").end()
.from(stepCont).next(someDecider).on("timeout").to(stepTimeout)
.from(stepCont).from(someDecider).on("continue").to(stepCont)
.from(stepCont).from(someDecider).on("COMPLETED").end()
.end()
.build();
来源:https://stackoverflow.com/questions/24307020/creating-a-decider-step-loop-with-spring-java-config