我在Spring Batch中遇到了以下设计缺陷。
因此,在Split Flow中,最终Step没有Next属性,如果有一个Decider守护它,那么它必须有Next属性。所以它不应该具有该属性,但它也需要它。赶上22。
示例:
<!-- Process parallel steps -->
<split id="split01">
<flow>
<step id="step1" next="step02">
<!-- Do something -->
</step>
<step id="step02">
<!-- Do something else -->
</step>
</flow>
<flow>
<step id="step03">
<!-- Do something -->
</step>
<!-- Only run under specific conditions -->
<decision id="decideToRunStep04" decider="isStepNeededDecider" >
<next on="RUN" to="step04"/>
<!-- Other state is "SKIP" -->
</decision>
<step id="step04">
<!-- Conditionally do something-->
</step>
</flow>
</split>
<step id="step05" >
<!-- Some more stuff -->
</step>
这似乎是春天人们会想到的东西,所以很奇怪正确,非黑客的方法是什么。感谢。
答案 0 :(得分:8)
鉴于此人没有得到任何答案,我将提供我正在使用的黑客攻击。它不漂亮,但春天也不是。
创建No Op Tasklet以在No Op步骤中使用。
public class NoopTasklet implements Tasklet {
@Override
public RepeatStatus execute(final StepContribution contribution,
final ChunkContext chunkContext) throws Exception {
return RepeatStatus.FINISHED;
}
}
将NOOP tasklet添加到原始示例
的决策块中<!-- Does nothing -->
<bean id="noopTasklet" class="com.foo.NoopTasklet" />
<!-- From example in question
<decision id="decideToRunStep04" decider="isStepNeededDecider" >
<next on="RUN" to="step04"/>
<next on="SKIP" to="noop01"/>
</decision>
<step id="step04">
<!-- Conditionally do something-->
</step>
<step id="noop01">
<!-- Does nothing in the SKIP case
<tasklet ref="noopTasklet" />
</step>
答案 1 :(得分:2)
春天是城里最漂亮的代码。 那说:
<step id="step1" parent="s1">
<end on="FAILED" />
<next on="COMPLETED WITH SKIPS" to="errorPrint1" />
<next on="*" to="step2" />
</step>
记录于http://docs.spring.io/spring-batch/reference/html/configureStep.html。
答案 2 :(得分:0)
以XML
<batch:decision id="customerDecision" decider="customerDecider">
<batch:next on="FILE_FAILURE" to="fileFailureStep" />
<batch:next on="FILE_GENERATION" to="loadData" />
</batch:decision>
在customerDecider类中
public class CustomerDecider implements JobExecutionDecider {
@Override
public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecutionStatus) {
If(x)
return new FlowExecutionStatus("FILE_FAILURE") ;
else
return new FlowExecutionStatus("FILE_GENERATION") ;
}
}