Creating a 'decider-step-loop' with spring-java-config

做~自己de王妃 提交于 2019-12-24 02:21:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!