Web services 如何使用RESTWeb服务触发作业?
我想使用CXF或jersey创建一个RESTWeb服务来调用spring批处理作业。有可能吗。如果是这样,我该怎么做?您可以从rest Put/Post方法开始spring批处理。因为CXF使用spring,所以将spring批处理与CXF一起使用更简单Web services 如何使用RESTWeb服务触发作业?,web-services,spring-batch,Web Services,Spring Batch,我想使用CXF或jersey创建一个RESTWeb服务来调用spring批处理作业。有可能吗。如果是这样,我该怎么做?您可以从rest Put/Post方法开始spring批处理。因为CXF使用spring,所以将spring批处理与CXF一起使用更简单 @Autowired private JobLauncher jobLauncher; @Autowired private Job job; public boolean startJob() throws Ex
@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;
}
我认为只有当
JobLauncher.run()
启动一个同步线程时(从JobLauncher.run()javadoc
:如果它同步返回,JobExecution才有效。如果实现是异步的,状态很可能未知。)是的,JobLauncher.run()在同步线程中启动。如果你需要异步,你可以在另一个线程中开始工作(如果你有更好的解决方案,请告诉我@bellabax以获取我的知识)。您可以使用Async webservice方法更新回状态(cxf提供注释Async,您可以使用它实现aync webservice)。这不是一个要求代码的地方!试试你自己,如果你在发布你的问题时遇到麻烦,我们将很乐意帮助你!