* job launcher register
This commit is contained in:
@@ -1,4 +1,45 @@
|
|||||||
package com.example.springbatch.controller;
|
package com.example.springbatch.controller;
|
||||||
|
|
||||||
|
import org.springframework.batch.core.Job;
|
||||||
|
import org.springframework.batch.core.JobParameters;
|
||||||
|
import org.springframework.batch.core.JobParametersBuilder;
|
||||||
|
import org.springframework.batch.core.JobParametersInvalidException;
|
||||||
|
import org.springframework.batch.core.launch.JobLauncher;
|
||||||
|
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
|
||||||
|
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
|
||||||
|
import org.springframework.batch.core.repository.JobRestartException;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
@ResponseBody
|
||||||
public class MainController {
|
public class MainController {
|
||||||
|
|
||||||
|
private final JobLauncher jobLauncher;
|
||||||
|
private final Job jobFirst;
|
||||||
|
|
||||||
|
public MainController(JobLauncher jobLauncher, Job jobFirst) {
|
||||||
|
this.jobLauncher = jobLauncher;
|
||||||
|
this.jobFirst = jobFirst;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/")
|
||||||
|
public String mainApi(@RequestParam("value") String value) {
|
||||||
|
|
||||||
|
JobParameters jobParameters = new JobParametersBuilder()
|
||||||
|
.addString("value", value)
|
||||||
|
.toJobParameters();
|
||||||
|
|
||||||
|
try {
|
||||||
|
jobLauncher.run(jobFirst, jobParameters);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
return "ok";
|
||||||
|
}
|
||||||
|
|
||||||
|
//https://docs.spring.io/spring-batch/reference/job/configuring-launcher.html
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ spring.datasource-data.username=user1
|
|||||||
spring.datasource-data.password=vmfhaltmskdls123
|
spring.datasource-data.password=vmfhaltmskdls123
|
||||||
|
|
||||||
|
|
||||||
spring.batch.job.enabled=true
|
spring.batch.job.enabled=false
|
||||||
spring.batch.job.name=firstJob
|
#spring.batch.job.name=firstJob
|
||||||
spring.batch.jdbc.initialize-schema=always
|
spring.batch.jdbc.initialize-schema=always
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user