* job launcher register

This commit is contained in:
kimjihun
2024-07-17 07:07:46 +09:00
parent 440946223e
commit 3e2e86e870
2 changed files with 43 additions and 2 deletions

View File

@@ -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
} }

View File

@@ -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