问题
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?
回答1:
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;
}
来源:https://stackoverflow.com/questions/20248910/how-to-trigger-a-job-using-a-rest-web-service