Spring batch Spring批处理-调用为webservice
我有一份春季批量工作。我是Spring Batch的新手,总是通过CommandLineJobRunner调用我 我的电话是这样的:Spring batch Spring批处理-调用为webservice,spring-batch,Spring Batch,我有一份春季批量工作。我是Spring Batch的新手,总是通过CommandLineJobRunner调用我 我的电话是这样的: org.springframework.batch.core.launch.support.CommandLineJobRunner spring-batch-myProject.xml SpringJobBean.MyProjectImportDataJob 现在我必须从webservice(SpringMVC)中调用批处理作业。在我的端点中,这是调用。我需要
org.springframework.batch.core.launch.support.CommandLineJobRunner spring-batch-myProject.xml SpringJobBean.MyProjectImportDataJob
现在我必须从webservice(SpringMVC)中调用批处理作业。在我的端点中,这是调用。我需要调用if语句中的批处理作业。我该怎么做?我读过JobLauncher…但不知道如何告诉它要启动什么
protected Object invokeInternal(Object aObj) throws Exception {
RunDataProcessingImportRequest request = (RunDataProcessingImportRequest) aObj;
RunDataProcessingImportResponse response = new RunDataProcessingImportResponse();
if (request.getDataProcessingType().equals(PROJECT_TYPE)){
response.setResultCd(1);
} else {
response.setResultCd(0);
response.setErrorCode(1l);
response.setErrorMessage("Incorrect process type");
}
return response;
}
这个问题的答案实际上取决于您使用的Spring批处理的版本 如果您使用的是2.0.x或更早版本,那么可以使用SpringBatch Admin为启动/停止/etc作业提供REST端点。您只需将JAR添加到应用程序中,并提供少量配置 如果您使用的是2.2.x或更高版本,并且允许您使用SpringBatch Admin的快照版本,则如上所述同样适用 如果您对使用Spring Batch Admin不感兴趣,则需要编写自己的端点并从那里启动作业。但是,它应该相当简单(我还没有测试下面的代码): 上面的代码假设您有多个作业可以执行。如果没有,您可以根据需要将
@Autowire
作业本身插入控制器(而不是作业注册表
)
您可以在此处阅读有关春季REST服务的更多信息:
您可以在此处阅读有关JobLauncher
的更多信息:
最后,您可以在第4.6.2节中阅读更多关于作业注册表的信息:
@Controller
public class JobLaunchingController {
@Autowire
JobLauncher jobLauncher;
@Autowire
JobRegistry jobRegistry;
@RequestMapping("/launch")
public @ResponseBody JobExecution launch(
@RequestParam(value="name", required=true) String name,
@RequestParam(value="params", required=false) String params) {
Job job = jobRegistry.getJob(name);
JobParametersBuilder paramsBuilder = new JobParametersBuilder();
if(params != null) {
// parse job parameters
}
return jobLauncher.run(job, paramsBuilder.toJobParameters());
}
}