如何使用休息网络服务触发作业? [英] How to trigger a job using a rest web service?
本文介绍了如何使用休息网络服务触发作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用 CXF 或 jersey 创建一个休息 Web 服务来调用 Spring 批处理作业.是否可以.如果是这样,我该怎么做?
I want to create a rest web service using CXF or jersey to invoke a spring batch job. Is it possible. If so, how can I do that?
推荐答案
您可以从您的 rest Put/Post 方法启动 spring 批处理.由于 CXF 使用 spring,因此使用带有 cxf 的 spring 批处理更简单
You can start the spring batch from your rest Put/Post method. Since CXF uses spring its simpler to use spring batch with cxf
@Autowired
private JobLauncher jobLauncher;
@Autowired
private Job job;
public boolean startJob()
throws Exception {
try {
final JobParameters jobParameters = new JobParametersBuilder().addLong("time", System.nanoTime()).toJobParameters();
final JobExecution execution = jobLauncher.run(job, jobParameters);
final ExitStatus status = execution.getExitStatus();
if (ExitStatus.COMPLETED.getExitCode().equals(status.getExitCode())) {
result = true;
}
}
} catch (JobExecutionAlreadyRunningException ex) {
} catch (JobRestartException ex) {
} catch (JobInstanceAlreadyCompleteException ex) {
} catch (JobParametersInvalidException ex) {
}catch (IOException ex) {
}
return false;
}
这篇关于如何使用休息网络服务触发作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文