我想制作一个Spring Batch,但我没有相关经验。
每个批处理步骤之间是否可以传递信息,还是它们必须完全独立?
例如,如果我有:
<batch:step id="getSQLs" next="runSQLs">
<batch:tasklet transaction-manager="TransactionManager"
ref="runGetSQLs" />
</batch:step>
<batch:step id="runSQLs">
<batch:tasklet transaction-manager="TransactionManager"
ref="runRunSQLs" />
</batch:step>
当getSQLs触发一个bean时,该bean会执行一个类来生成一个类型为String的列表。是否可以引用该列表以供runSQLs触发的bean使用?(“触发”可能不是正确的术语,但我认为你知道我的意思)
更新: 因此,getSQLs步骤会触发此bean:
<bean id="runGetSQLs" class="myTask"
scope="step">
<property name="filePath" value="C:\Users\username\Desktop\sample.txt" />
</bean>
触发myTask类,该类执行此方法:
@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
ExecutionContext stepContext = this.stepExecution.getExecutionContext();
stepContext.put("theListKey", sourceQueries);
return RepeatStatus.FINISHED;
}
我需要在execute方法中传递stepExecution吗?
BATCH_JOB_EXECUTION_CONTEXT.SERIALIZED_CONTEXT
中存储中间数据并不是最佳解决方案。需要在作业步骤之间传递数据的要求意味着您违反了批处理的理念)) - gavenkoa