2
我試圖運行面向分區的作業,並無法訪問stepExecutionContext存儲的數據。這是我的工作定義如何將先前的步驟數據傳遞給分區器
<batch:job id="job1" restartable="false" incrementer="idIncrementer">
<batch:step id="readwritestep" next="partitionStep">
<batch:tasklet transaction-manager="transactionManager">
<batch:chunk reader="reader1"
writer="writer1"
commit-interval="500"/>
</batch:tasklet>
<batch:listeners>
<batch:listener ref="promotionListener"/>
</batch:listeners>
</batch:step>
<batch:step id="partitionStep" >
<batch:partition step="detailsStep" partitioner="partitioner">
<batch:handler grid-size="10" task-executor="taskExecutor" />
</batch:partition>
</batch:step>
</batch:job>
<batch:step id="detailsStep">
<batch:tasklet transaction-manager="transactionManager">
<batch:chunk reader="reader2"
processor="processor"
writer="writer2"
commit-interval="1500"/>
</batch:tasklet>
</batch:step>
在處理readwritestep我存儲步驟方面的一些數據和促進就業方面,這樣我可以在partioner訪問。但我已經實現的自定義partioner沒有任何參考的父步驟,我可以訪問存儲的數據...即使partitioner被綁定到STEP它不能訪問父步驟數據...我在這裏錯過了什麼嗎?一個選項分區程序給出的是jdbctemplate來生成分割上下文,我不在intrest。我試圖注入@beforestep註釋來訪問上下文數據,但它沒有被調用..我不想執行JDBC讀取以生成從屬數據...我想要獲取LIST數據存儲在步驟/工作方面的執行和產生分流背景下...有人可以幫我點我到正確的方向,這樣我可以訪問這些數據......
這裏是劃分階級...
public class ProductDetailsPartitioner implements Partitioner {
private List<Product> prds;
@Override
public Map<String, ExecutionContext> partition(int gridSize) {
List<String> referencIds = new ArrayList<String>();
for (Product prd : prds) {
referencIds.add(prd.getReferenceId());
}
Map<String, ExecutionContext> results = new LinkedHashMap<String,ExecutionContext>();
for (String referencId : referencIds) {
ExecutionContext context = new ExecutionContext();
context.put("referenceId", referencId);
results.put("partition." + referencId, context);
}
return results;
}
@BeforeStep
public void retrieveInterstepData(StepExecution stepExecution) {
System.out.println("Entered Before step in partion");
JobExecution jobExecution = stepExecution.getJobExecution();
ExecutionContext jobContext = jobExecution.getExecutionContext();
System.out.println("ExecutionContext"+jobContext);
this.prds = (List<Product>) jobContext.get("products");
}
}
你可以添加一些代碼來顯示你做了什麼嗎? – Kilokahn
作爲「分區器」的同一個singleton「Spring bean」也可以作爲「偵聽器」來獲取任何上下文關鍵字,以決定分區算法step3ecution.getJobExecution()。getExecutionContext()。get(「key」) – kisna