* 배치2 정의 중
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package com.example.springbatch.batch;
|
||||
|
||||
import com.example.springbatch.entity.WinEntity;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.job.builder.JobBuilder;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.builder.StepBuilder;
|
||||
import org.springframework.batch.item.data.RepositoryItemReader;
|
||||
import org.springframework.batch.item.data.builder.RepositoryItemReaderBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
@@ -20,18 +23,26 @@ public class SecondBatch {
|
||||
this.platformTransactionManager = platformTransactionManager;
|
||||
}
|
||||
|
||||
// @Bean
|
||||
// public Job secondJob() {
|
||||
//
|
||||
// return new JobBuilder("secondJob", jobRepository)
|
||||
// .start()
|
||||
// .build();
|
||||
// }
|
||||
//
|
||||
// @Bean
|
||||
// public Step secondStep() {
|
||||
//
|
||||
// return new StepBuilder("secondStep", jobRepository)
|
||||
// .build();
|
||||
// }
|
||||
@Bean
|
||||
public Job secondJob() {
|
||||
|
||||
return new JobBuilder("secondJob", jobRepository)
|
||||
.start(secondStep())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step secondStep() {
|
||||
|
||||
return new StepBuilder("secondStep", jobRepository)
|
||||
.<WinEntity, WinEntity> chunk(10, platformTransactionManager)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public RepositoryItemReader<WinEntity> winReader() {
|
||||
|
||||
return new RepositoryItemReaderBuilder<WinEntity>()
|
||||
.name("")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
package com.example.springbatch.batch;
|
||||
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.Step;
|
||||
import org.springframework.batch.core.job.builder.JobBuilder;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.builder.StepBuilder;
|
||||
import org.springframework.batch.item.ItemProcessor;
|
||||
import org.springframework.batch.item.ItemReader;
|
||||
import org.springframework.batch.item.ItemWriter;
|
||||
import org.springframework.batch.item.support.ListItemReader;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Configuration
|
||||
public class ThirdBatch {
|
||||
|
||||
private final JobRepository jobRepository;
|
||||
private final PlatformTransactionManager platformTransactionManager;
|
||||
|
||||
public ThirdBatch(JobRepository jobRepository, PlatformTransactionManager platformTransactionManager) {
|
||||
this.jobRepository = jobRepository;
|
||||
this.platformTransactionManager = platformTransactionManager;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Job thirdJob() {
|
||||
|
||||
System.out.println("third job");
|
||||
|
||||
return new JobBuilder("thirdJob", jobRepository)
|
||||
.start(thirdStep())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Step thirdStep() {
|
||||
|
||||
System.out.println("third step");
|
||||
|
||||
return new StepBuilder("thirdStep", jobRepository)
|
||||
.<String, String> chunk(3, platformTransactionManager)
|
||||
.reader(thirdReader())
|
||||
.processor(upperProcessor())
|
||||
.writer(thirdWriter())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ItemReader<String> thirdReader() {
|
||||
|
||||
return new ListItemReader<>(Arrays.asList("kim", "lee", "park", "choi", "jeong", "ha", "jo"));
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ItemProcessor<String, String> upperProcessor() {
|
||||
|
||||
return item -> item.toUpperCase();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ItemWriter<String> thirdWriter() {
|
||||
|
||||
return item -> item.forEach(System.out::println);
|
||||
}
|
||||
}
|
||||
@@ -37,24 +37,5 @@ public class MainController {
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@GetMapping("/third")
|
||||
public String thirdApi(@RequestParam("value") String value) {
|
||||
|
||||
System.out.println(value);
|
||||
|
||||
JobParameters jobParameters = new JobParametersBuilder()
|
||||
.addString("date", value)
|
||||
// .addLong()
|
||||
.toJobParameters();
|
||||
|
||||
try {
|
||||
jobLauncher.run(jobRegistry.getJob("thirdJob"), jobParameters);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
return "ok";
|
||||
}
|
||||
|
||||
//https://docs.spring.io/spring-batch/reference/job/configuring-launcher.html
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@ package com.example.springbatch.repository;
|
||||
import com.example.springbatch.entity.WinEntity;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface WinRepository extends JpaRepository<WinEntity, Long> {
|
||||
|
||||
|
||||
Optional<WinEntity> findByWinGreaterThanEqual(Long win);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user