Spring Batch SplitBuilder不执行启动流程

时间:2014-05-01 02:46:31

标签: java spring spring-batch spring-java-config

我使用Spring Batch(2.2.6.RELEASE)FlowBuilder.SplitBuilder在Java Config类中声明一个流,该类并行执行3个子流:

@Bean
public SimpleFlow mainFlow() {
    return new FlowBuilder<SimpleFlow>("Main Flow")
            .start(flow1())
            .split(new SimpleAsyncTaskExecutor())
            .add(flow2(), flow3())
            .build();
}

此语法来自spring-batch FlowBuilder.SplitBuilder javadoc

但是,flow1永远不会被执行;只执行flow2flow3

对我来说这看起来像个错误...你觉得怎么样?

可以在此github存储库的ParallelFlowsJobConfigTest类中找到junit测试:https://github.com/galak75/spring-batch-labs

1 个答案:

答案 0 :(得分:2)

这对我有用:

@Bean
public SimpleFlow mainFlow() {
    SimpleFlow splitFlow = new FlowBuilder<SimpleFlow>("Split Flow")
        .split(new SimpleAsyncTaskExecutor())
        .add(flow2(), flow3())
        .build();
    return new FlowBuilder<SimpleFlow>("Main Flow")
        .start(flow1())
        .next(splitFlow)
        .end();
}

重要的细节是“下一个(...)”以及狭缝应该在自己的子流中的事实。