2013-04-23 132 views
0

我正在使用Spring Batch Admin爲我們的系統運行批處理作業。我們必須多次運行這些工作。我正在使用spring batch admin的其餘界面。我使用Spring RestTemplate開始一項新工作。使用具有相同作業名稱的REST在Spring批處理管理器中運行多個作業

RestTemplate tpl = new RestTemplate(); 
tpl.postForLocation(Constants.SPRING_BATCH_ADMIN_URL + "/jobs/myBatchJob; 

這可以啓動第一份工作,但在後續工作中,請求不會啓動新工作實例。在作業的配置文件我有一個jobParmatersIncrementer通過點擊啓動按鈕定義

<job id="myBatchJob" xmlns="http://www.springframework.org/schema/batch" 
    restartable="true" incrementer="jobParametersIncrementer"> 
    <bean id="jobParametersIncrementer" 
     class="org.springframework.batch.core.launch.support.RunIdIncrementer" /> 

我試圖改變我的postForLocation到

List<JobInstance> jobInstances = jobExplorer.getJobInstances("myBatchJob", 0, 30); 
JobParameters jobParameters = jobInstances.get(0).getJobParameters(); 
RunIdIncrementer runIdIncrementer = new RunIdIncrementer(); 
JobParameters jobParameters = runIdIncrementer.getNext(jobParameters); 
RestTemplate tpl = new RestTemplate(); 
tpl.postForLocation(Constants.SPRING_BATCH_ADMIN_URL + 
    "/jobs/myBatchJob?launch=Launch&{parameters}", 
    "runid", 
    jobParameters.toString()); 

它從春天批次管理頁面的作品。這是在參數編輯框中

run.id(long)=1 

如何在不同的Web應用程序中多次運行Spring Batch Admin的作業?

回答

0

你也可以傳遞參數jobParameter請求體,攜帶您的元組

jobParameters=run.id(long)=123 

並將其安裝URL編碼的POST請求。這是我的jQuery解決方案。

$.post('<url>/jobs/myBatchJob', 'jobParameters=' + encodeURIComponent('run.id(long)=123')).done(function() { 
    // do something 
}); 
相關問題