如何使用休息Web服务触发作业?

时间:2013-11-27 17:16:15

标签: web-services spring-batch

我想使用CXF或jersey创建一个休息Web服务来调用spring批处理作业。可能吗。如果是这样,我该怎么做?

1 个答案:

答案 0 :(得分:0)

您可以从剩余的Put / Post方法开始弹簧批次。由于CXF使用spring,因此使用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;
    }