2011-12-16 46 views
2

可處理當前的資源有什麼辦法讓currentResource通過MultiResourceItemReader處理,以使其在beforeStep method.Kindly可以提供我一個工作代碼示例。我試圖在給stepexecutionlistener注入multiresourcereader參考,但彈簧的cglib只接受一個接口類型被注入,我不知道是否使用ItemReaderItemStream接口。我想MultiResourceItemReader在beforeStep方法

+0

任何人都請。 – 2011-12-16 09:58:54

+0

我建議你仔細設置與你的問題相關的標籤以獲得更多的觀衆。我不知道什麼是主題/應用程序/無論你在說什麼,但我確定它不是Windows批處理文件(即「批處理」標記的目標)。 – Aacini 2011-12-16 11:52:23

回答

1
  • currentResource正在從MultiResourceItemReader獲取當前不可能。如果您需要此API增強功能,請在Spring Batch JIRA中創建一個。
  • 即使currentResource有一個吸氣劑,它的值在beforeStep()無效。它在open()close()之間有效。
1

它是可能的,如果使用Partition StepBinding Input Data to Steps概念

簡單的代碼例如,具有併發限制1模仿 「串行」 處理:

<bean name="businessStep:master" class="org.springframework.batch.core.partition.support.PartitionStep"> 
    <property name="jobRepository" ref="jobRepository"/> 
    <property name="stepExecutionSplitter"> 
     <bean class="org.springframework.batch.core.partition.support.SimpleStepExecutionSplitter"> 
      <constructor-arg ref="jobRepository"/> 
      <constructor-arg ref="concreteBusinessStep"/> 
      <constructor-arg> 
       <bean class="org.spring...MultiResourcePartitioner" scope="step"> 
        <property name="resources" value="#{jobParameters['input.file.pattern']}"/> 
       </bean> 
      </constructor-arg> 
     </bean> 
    </property> 
    <property name="partitionHandler"> 
     <bean class="org.springframework.batch.core.partition.support.TaskExecutorPartitionHandler"> 
      <property name="taskExecutor"> 
       <bean class="org.springframework.core.task.SimpleAsyncTaskExecutor"> 
        <property name="concurrencyLimit" value="1" /> 
       </bean> 
      </property> 
      <property name="step" ref="concreteBusinessStep"/> 
     </bean> 
    </property> 
</bean> 

<bean id="whateverClass" class="..." scope="step"> 
    <property name="resource" value="#{stepExecutionContext['fileName']}" /> 
</bean> 

示例步驟的配置:

<job id="renameFilesPartitionJob">   
    <step id="businessStep" 
      parent="businessStep:master" /> 
</job> 

<step id="concreteBusinessStep"> 
    <tasklet> 
     <chunk reader="itemReader" 
       writer="itemWriter" 
       commit-interval="5" /> 
    </tasklet> 
</step> 

潛在缺點:

  • 不同的步驟對每個文件,而不是一個步驟
  • 更復雜的配置
3

MultiResourceItemReadernow has的方法getCurrentResource()返回當前Resource