spring batch : scheduling
This commit is contained in:
@@ -3,9 +3,11 @@ package com.example.springbatch;
|
|||||||
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
|
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableBatchProcessing
|
@EnableBatchProcessing
|
||||||
|
@EnableScheduling
|
||||||
public class SpringBatchApplication {
|
public class SpringBatchApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.example.springbatch.application.scheduler;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
@Scheduled(fixedDelay = 5000)
|
||||||
|
public void runCreateArticleJob() throws Exception{
|
||||||
|
jobLauncher.run(createArticleJob, new JobParametersBuilder()
|
||||||
|
.addDate("date", new Date())
|
||||||
|
.toJobParameters());
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -16,7 +16,7 @@ spring:
|
|||||||
batch:
|
batch:
|
||||||
initialize-schema: always
|
initialize-schema: always
|
||||||
job:
|
job:
|
||||||
names: ${job.name:createArticleJob}
|
names: ${job.name:NONE}
|
||||||
# # 데이터베이스 분리 방법 (1)
|
# # 데이터베이스 분리 방법 (1)
|
||||||
# schema: schema-mysql.sql
|
# schema: schema-mysql.sql
|
||||||
# table-prefix: batch.BATCH_
|
# table-prefix: batch.BATCH_
|
||||||
|
|||||||
Reference in New Issue
Block a user