spring batch : batch api
This commit is contained in:
@@ -22,6 +22,8 @@ dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-batch'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jdbc'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
|
||||
compileOnly 'org.projectlombok:lombok'
|
||||
developmentOnly 'org.springframework.boot:spring-boot-devtools'
|
||||
runtimeOnly 'mysql:mysql-connector-java'
|
||||
|
||||
1
spring-batch/http/job.http
Normal file
1
spring-batch/http/job.http
Normal file
@@ -0,0 +1 @@
|
||||
http://localhost:8080//jobs/create-articles
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.example.springbatch.application.controller;
|
||||
|
||||
import com.example.springbatch.application.service.JobService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/jobs")
|
||||
@RequiredArgsConstructor
|
||||
public class JobController {
|
||||
|
||||
private final JobService jobService;
|
||||
|
||||
@GetMapping("/create-articles")
|
||||
public void runCreateArticleJob() throws Exception {
|
||||
jobService.runCreateArticleJob();
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,17 @@
|
||||
package com.example.springbatch.application.scheduler;
|
||||
|
||||
import com.example.springbatch.application.service.JobService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Configuration
|
||||
@RequiredArgsConstructor
|
||||
public class JobScheduler {
|
||||
|
||||
private final Job createArticleJob;
|
||||
private final JobLauncher jobLauncher;
|
||||
private final JobService jobService;
|
||||
|
||||
@Scheduled(fixedDelay = 5000)
|
||||
// @Scheduled(fixedDelay = 5000)
|
||||
public void runCreateArticleJob() throws Exception{
|
||||
jobLauncher.run(createArticleJob, new JobParametersBuilder()
|
||||
.addDate("date", new Date())
|
||||
.toJobParameters());
|
||||
jobService.runCreateArticleJob();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.example.springbatch.application.service;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class JobService {
|
||||
|
||||
private final Job createArticleJob;
|
||||
private final JobLauncher jobLauncher;
|
||||
|
||||
public void runCreateArticleJob() throws Exception{
|
||||
jobLauncher.run(createArticleJob, new JobParametersBuilder()
|
||||
.addDate("date", new Date())
|
||||
.toJobParameters());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user