#29 pass: spring batch simple example

This commit is contained in:
haerong22
2022-12-23 01:22:02 +09:00
parent 4840835d4e
commit b0b5fbde6d
3 changed files with 38 additions and 1 deletions

View File

@@ -1,11 +1,43 @@
package com.example.passbatch;
import lombok.RequiredArgsConstructor;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@EnableBatchProcessing
@SpringBootApplication
@RequiredArgsConstructor
public class PassBatchApplication {
private final JobBuilderFactory jobBuilderFactory;
private final StepBuilderFactory stepBuilderFactory;
@Bean
public Step passStep() {
return this.stepBuilderFactory.get("passStep")
.tasklet((contribution, chunkContext) -> {
System.out.println("Execute PassStep");
return RepeatStatus.FINISHED;
}).build();
}
@Bean
public Job passJob() {
return this.jobBuilderFactory.get("passJob")
.start(passStep())
.build();
}
public static void main(String[] args) {
SpringApplication.run(PassBatchApplication.class, args);
}

View File

@@ -0,0 +1,6 @@
spring:
datasource:
url: jdbc:h2:mem:mydb
username: pass_local
password: 1234
driver-class-name: org.h2.Driver