2013-01-22 45 views
0

我们正在开发Spring批处理作业,在这里我们需要存储一步计算出的数据并在下一步中检索它。无法将数据从一个步骤存储到另一个步骤 - 在Spring批处理作业

我能够以独立的方式来实现这一目标使用Spring Batch的源

http://static.springsource.org/spring-batch/reference/html/patterns.html#passingDataToFutureSteps

下面的实现,但我们在客户端/ MASTER和SERVER方式来实现它。客户/主人的代码与作业和分区相关。

客户端位于EAR外侧,由Shell脚本用于调用批处理作业。

上的客户端侧

豆配置:

<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代码:

<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的作为网络服务器。

请指导我们解决问题。

回答

1

将信息从分区程序传递给执行程序(步骤),您可以在分区时在stepExecutionContext中设置它,然后使用迟绑定来设置值。看看这里的例子(https://github.com/SpringSource/spring-batch/blob/master/spring-batch-samples/src/main/resources/jobs/partitionJdbcJob.xml),并特别关注这个值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)了解更多信息。

+0

谢谢,我们可以通过覆盖作业的分区程序并将所需的值从客户端传递到定义步骤的从属端代码来传递值。 – techanuva

相关问题