我们正在开发一个Spring Batch Job,我们需要在一个步骤中存储计算的数据并在下一步中检索它 .
我可以使用 spring 批处理源中的以下实现以独立方式实现此目的
http://static.springsource.org/spring-batch/reference/html/patterns.html#passingDataToFutureSteps
但我们正在以CLIENT / MASTER和SERVER方式实现它 . CLIENT / MASTER具有与作业和分区相关的代码 .
客户端在EAR之外,并由Shell脚本用于调用批处理作业 .
客户端的Bean配置:
<job id="esk956" xmlns="http://www.springframework.org/schema/batch">
<step id="importSalesAlert-master">
<partition handler="partitionHandler" partitioner="partitioner" />
</step>
</job>
<bean id="partitioner"
class="org.springframework.batch.core.partition.support.SimplePartitioner" />
与步骤及其实现(读者,处理器和写入器)相关的所有代码都在SERVER / SLAVE端 .
SLAVE CODE:
<step id="importSalesAlert" xmlns="http://www.springframework.org/schema/batch">
<tasklet transaction-manager="transactionManager">
<chunk reader="salesAlertFileItemReader" processor="nucleusItemProcessor"
writer="nucleusItemWriter" commit-interval="10" />
<listeners>
<listener ref="loggingStepListener" />
</listeners>
</tasklet>
</step>
我们使用JMS集成和Weblogic作为Web服务器 .
请指导我们解决问题 .
1 回答
将信息从分区程序传递给执行程序(步骤),您可以在分区时在stepExecutionContext中设置它,然后使用后期绑定来设置值 . 看看这里的例子(https://github.com/SpringSource/spring-batch/blob/master/spring-batch-samples/src/main/resources/jobs/partitionJdbcJob.xml),特别注意 Value itemReader中的
${stepExecutionContext[minValue]}
. 此值来自分区程序设置的stepExecutionContext .您也可以以相同的方式访问其他后期绑定变量,就像jobExecutionContext和jobParameters一样 . 只需确保你的itemreader在它的根元素中具有属性
scope="step"
,并且你要么使用命名空间来声明你的jobRepository<batch:job-repository.../>
或声明<bean class="org.springframework.batch.core.scope.StepScope" />
bean(但是没有两者) . 有关详细信息,请参阅此处(http://static.springsource.org/spring-batch/reference/html-single/index.html#step-scope) .