是否有可能在運行時在Spring Batch中獲取已定義作業的列表而不使用數據庫?也許可以從jobRepository
bean或某些類似的對象獲取這些元數據?Spring批處理:在運行時獲取已定義作業的列表
7
A
回答
5
可以使用JobExplorer.getJobNames()
檢索所有作業名稱的列表。
你首先要確定使用JobExplorerFactoryBean
的jobExplorer
豆:
<bean id="jobExplorer" class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
<property name="dataSource" ref="dataSource"/>
</bean>
,然後當你需要它,你可以注入這個bean。
+0
它的工作原理,但它使用分貝。有沒有辦法找到它沒有數據庫? –
1
獲取配置爲bean的作業名稱列表的替代策略可以使用ListableJobLocator。
@Autowired
ListableJobLocator jobLocator;
....
jobLocator.getJobNames();
這不需要作業存儲庫。
0
我使用這些代碼列出並執行作業
private String jobName = "";
private JobLauncher jobLauncher = null;
private String selectedJob;
private String statusJob = "Exit Status : ";
private Job job;
ApplicationContext context;
private String[] lstJobs;
/**
* Execute
*/
public ExecuteJobBean() {
this.context = ApplicationContextProvider.getApplicationContext();
this.lstJobs = context.getBeanNamesForType(Job.class);
if (jobLauncher == null)
jobLauncher = (JobLauncher) context.getBean("jobLauncher");
}
/**
* Execute
*/
public void executeJob() {
setJob((Job) context.getBean(this.selectedJob));
try {
statusJob = "Exit Status : ";
JobParameters jobParameters = new JobParametersBuilder().addLong("time", System.currentTimeMillis()).toJobParameters();
JobExecution execution = jobLauncher.run(getJob(), jobParameters);
this.statusJob = execution.getStatus() + ", ";
} catch (Exception e) {
e.printStackTrace();
this.statusJob = "Error, " + e.getMessage();
}
this.statusJob += " Done!!";
}
相關問題
- 1. Spring-xd批處理作業鎖定
- 2. 使用spring批處理獲取執行列表時發生java.lang.IllegalAccessError
- 3. 在Spring批處理中查詢批處理作業元數據
- 4. 如何按特定順序運行Spring批處理作業(Spring Boot)?
- 5. 批處理mysql腳本/計劃運行批處理作業
- 6. 以編程方式運行Spring批處理作業?
- 7. Spring批處理作業實例已存在
- 8. Spring批處理作業信息庫
- 9. 啓動Spring批處理作業
- 10. NServiceBus批處理長時間運行的作業
- 11. 使用具有相同作業名稱的REST在Spring批處理管理器中運行多個作業
- 12. 如何安排批處理作業在特定時間點運行?
- 13. 查找在批處理作業中運行的代碼
- 14. 如何運行具有不同參數的Spring批處理作業?
- 15. Spring批處理作業執行iteraton使用註釋
- 16. 春季批處理作業在無限循環中運行
- 17. 春季批處理 - 作業執行ID?
- 18. Spring批處理:如何獲取所有行讀取的錯誤?
- 19. 批處理作業事務處理
- 20. spring批處理流作業Vs spring組合任務
- 21. 從pentaho中的批處理文件運行多個作業
- 22. 在使用json api執行spring批處理作業時傳遞文件名作爲作業參數
- 23. Spring批處理 - 如何生成一個批處理作業的輸出文件作爲excel表
- 24. Java批處理作業偵聽器在作業獲得作業ID後
- 25. Spring批處理作業讀取多個文件並寫入多個表
- 26. Spring批處理管理員:通過Web GUI安排新作業
- 27. 在Spring批處理中排隊作業實例
- 28. Howto在Spring批處理作業中完整數據集合?
- 29. Spring批處理並行處理
- 30. Spring XD:如何決定何時使用流或批處理作業?
你所說的「定義的工作」的意思是?本地應用程序環境中的作業?作業存儲庫中的作業?其他一些定義? –
我的意思是我在本地應用程序上下文中定義的所有工作 –
您可以使用像context.getBeanNamesForType(Job.class)這樣簡單的操作來完成此任務。 –