Spring Batch 5
- ์ต์ Java 17 ํ์
- @EnableBatchProcessing ์ด๋ ธํ ์ด์ ๊ถ์ฅ X ๐ ์ฌ์ฉํ ์ autoConfiguration ์ผ๋ถ ๊ธฐ๋ฅ ์ฌ์ฉ ๋ถ๊ฐ
Spring Batch ์ด๊ธฐ ์ค์
spring:
profiles:
active: local
batch:
job:
names: ${job.name:NONE}
---
spring:
config:
activate:
on-profile: local
datasource:
url: jdbc:mysql://127.0.0.1:3306/house
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password:
jpa:
show-sql: true
generate-ddl: false
hibernate:
ddl-auto: none
batch:
jdbc:
initialize-schema: ALWAYS
batch ๊ด๋ จํด์ initialize-schema: ALWAYS๋ก ์ค์ ํ๋ฉด DB schema๋ฅผ ์๋์ผ๋ก ์์ฑํ๋ค.
DB schema์๋ ์คํ์ ๋ณด์ ์ํ์ ๋ณด ๋ฑ์ ์ ์ฅํด ์คํ๋ง ๋ฐฐ์น์ ์คํ ๋ฐ ๊ด๋ฆฌ ๋ชฉ์ ์ผ๋ก ์ ์ฅ, ์ ๋ฐ์ดํธ, ์กฐํํ ์ ์๋ ๊ธฐ๋ฅ์ ์ ๊ณตํ๋ค.
์ด ๋ฉํ ํ ์ด๋ธ์ด ํ์์ ์ผ๋ก ์์ฑ๋์ด์ผ ํ๋ค !
โณ๏ธ Job ์์ฑ
- ๊ธฐ์กด Spring Batch 4์์๋ JobBuilderFactory๋ฅผ ์ฌ์ฉํด์ ์์ฑํ์์ง๋ง Spring Batch 5์์๋ deprecated ๋์๋ค.
- JobBuilder(String name, JobRepository jobRepository) ์ฌ์ฉ
- incrementer : Job ์คํ ํ์ ์ผ์ ํ๊ฒ ์ฆ๊ฐ
@Bean("myJob")
public Job helloJob(JobRepository jobRepository, Step helloStep){
return new JobBuilder("myJob", jobRepository)
.incrementer(new RunIdIncrementer())
.start(helloStep)
.build();
}
โณ๏ธ Step ์์ฑ
@JobScope
@Bean("myStep")
public Step helloStep(Tasklet myTasklet, JobRepository jobRepository, PlatformTransactionManager transactionManager) {
return new StepBuilder("myStep", jobRepository)
.tasklet(myTasklet, transactionManager)
.build();
}
โณ๏ธ Tasklet ์์ฑ
@StepScope
@Bean
public Tasklet myTasklet(){
return ((contribution, chunkContext) -> {
log.info(">>>>> This is Step1");
return RepeatStatus.FINISHED;
});
}
Spring Batch ์คํ ๋ฐฉ์
- Quartz Scheduler
- CI ํ๋ก๊ทธ๋จ ์ด์ฉ ๐ Jenkins
- ๋ง์คํฐ์์ ์ฌ๋ ์ด๋ธ๋ก ๋ช ๋ น์ ์ ๋ฌํด ๋ฐฐ์น ํ๋ก๊ทธ๋จ ์คํ
- Jenkins์์ ์ง์ํ๋ ์ค์ผ์ค๋ง ๊ธฐ๋ฅ์ ํตํด ์คํ
- Spring Cloud Data Flow
- Kubernetes ํด๋ฌ์คํฐ ๊ตฌ์ถ
์คํ์ํค๊ธฐ
๐น ์ธํ ๋ฆฌ์ ์ด๋ก ์คํ์ํค๊ธฐ
job ์ด๋ฆ์ myJob์ผ๋ก ์ค์ ํด์ ํด๋นํ๋ job ํ์ ํ ์คํ
๐น ํฐ๋ฏธ๋๋ก ์คํ์ํค๊ธฐ
java -jar build/libs/spring-batch-0.0.1-SNAPSHOT.jar --job.name=myJob
์ฐธ๊ณ ์๋ฃ
https://docs.spring.io/spring-batch/reference/schema-appendix.html
https://docs.spring.io/spring-batch/docs/5.0.4/reference/html/whatsnew.html
'Spring > Spring & Spring Boot' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Spring] Example<T> ์ธํฐํ์ด์ค (0) | 2025.03.11 |
---|---|
[Spring] Spring Batch๋ก ํ ๋ฌ ์ง๋ ๋ฐ์ดํฐ ์ญ์ ํ๊ธฐ (0) | 2024.07.29 |
[Spring/Spring Boot] SSE (Server-Sent Events)์ EventSource ์ ์ฉํด๋ณด๊ธฐ (0) | 2024.05.14 |
[Spring] Spring Security @AuthenticationPrincipal (0) | 2024.04.10 |
[Spring] ํํฐ(Filter)์ ์ธํฐ์ ํฐ(Interceptor) (0) | 2024.03.18 |