Spring Batch 입문 4편. v5 → v6 주요 변경점 (Spring Framework 7 · Spring Retry 제거 · 새 chunk processing · concurrency · CommandLineJobOperator · JFR · JSpecify · Lambda style) + 5분 Hello Job hands-on 까지 풀어쓴 학습 노트. Part 1 입문 마무리.
이 글은 Spring Batch 입문에서 운영까지 시리즈 48편 중 4편이에요. 3편 에서 Domain Language 11가지 를 잡았다면, 이번 4편은 v6 의 변경점 과 직접 만져보는 Hello Job. Part 1 입문의 마지막.
v6.0 의 주요 변경점
v5.x → v6.0 의 큰 변경 정리. v5 코드를 가진 분에게 마이그레이션 가이드, 새 시작하는 분에게 왜 6.0 권장 인지의 이유.
1. Dependency Upgrade
| 라이브러리 | v5 | v6 |
|---|---|---|
| Spring Framework | 6.x | 7.0 |
| Spring Integration | 6.x | 7.0 |
| Spring Data | 3.x | 4.0 |
| Spring LDAP | 3.x | 4.0 |
| Spring AMQP | 3.x | 4.0 |
| Spring Kafka | 3.x | 4.0 |
| Micrometer | 1.13 | 1.16 |
전체 Spring 생태계 동시 major bump. Java 17+ 필수.
2. Batch Infrastructure Configuration 개선
여기가 가장 큰 사용자 영향. v6 부터:
@EnableBatchProcessing // 기본 = ResourcelessJobRepository (학습용)
@EnableJdbcJobRepository // JDBC 기반 (운영)
@EnableMongoJobRepository // MongoDB 기반
또는 base class:
DefaultBatchConfiguration // 기본
JdbcDefaultBatchConfiguration // JDBC
MongoDefaultBatchConfiguration // MongoDB
핵심 변화 — DB 없이도 학습 가능 (ResourcelessJobRepository = DB 없이 메모리만 쓰는 저장소). 5·7편 깊이.
3. New Chunk-oriented Processing 모델
v6 = ChunkOrientedStep (chunk 처리를 1급으로 다루는 step) 신규 구현. 각 chunk 가 별도 transaction 으로 명확히 분리.
이전 (v5) 의 TaskletStep (단일 작업 한 덩어리 step) 위에 chunk 로직을 얹은 구조 → v6 = chunk 가 1급 step type. 더 명확한 설계.
4. New Concurrency Model
v6 = Java 21 Virtual Threads (JVM 경량 스레드) + StructuredTaskScope (구조화된 동시성 API) 활용. multi-threaded step·partition·remote chunking 의 thread 모델 현대화.
설정 단순:
@Bean
public Step concurrentStep(...) {
return new StepBuilder(...)
.<In, Out>chunk(100, tx)
.reader(...)
.writer(...)
.taskExecutor(Thread.ofVirtual().factory()) // Virtual Thread
.build();
}
5. CommandLineJobOperator
v6 신규 — CLI 에서 Job 실행·중지·재시작 의 표준 도구.
$ java -jar my-batch.jar --job=myJob --params=targetDate=2026-01-01
$ java -jar my-batch.jar --stop --execution-id=42
$ java -jar my-batch.jar --restart --execution-id=42
이전에 직접 main 메서드 작성 하던 패턴이 표준 인프라 로.
6. Failed Job Execution Recovery
새 recover 기능 — FAILED → RECOVERED 상태 변환:
jobOperator.recover(executionId);
운영자가 수동으로 실패 처리 한 job 을 RECOVERED 마킹 → 정리·재시작 흐름 명확.
7. Graceful Shutdown 지원
v6 = SIGTERM 받으면 진행 중인 chunk 까지 안전히 종료 → Kubernetes·Cloud 환경 친화.
spring.batch.job.gracefulShutdown.enabled: true
8. Observability — JFR 지원
JFR (Java Flight Recorder) = JDK 내장 프로파일러. v6 부터 Spring Batch 의 모든 이벤트 JFR event 로 노출. 45·46편에서 깊이.
9. JSpecify Null-Safety
JSpecify = 자바 null 표기 표준 라이브러리.
@Nullable
public Player read() { ... }
@NonNull
public Player process(@NonNull Player p) { ... }
표준 annotation = org.jspecify.annotations.*. IDE·tool 호환성 향상.
10. Local Chunking
v6 신규 — remote chunking 의 경량 버전. 같은 JVM 안에서 Manager-Worker chunk 분담 (관리자-작업자 역할 분리) 가능. 37편 scaling.
11. SEDA + Spring Integration
Staged Event-Driven Architecture — step 들을 message channel 로 연결. 42~44편 integration.
12. Jackson 3 지원
JSON reader·writer 가 Jackson 3 사용. Jackson 2 deprecated.
13. Remote Step
v6 신규 — Step 자체를 다른 JVM 에서 실행. partitioning 보다 더 유연.
14. Lambda Style Configuration
@Bean
public Step myStep(JobRepository repo, PlatformTransactionManager tx) {
return new StepBuilder("myStep", repo)
.<String, String>chunk(100, tx)
.reader(() -> "data") // lambda Reader
.processor(item -> item.toUpperCase()) // lambda Processor
.writer(chunk -> chunk.forEach(System.out::println)) // lambda Writer
.build();
}
간단한 step = anonymous class 안 만들고 lambda 한 줄. 학습·테스트에 자연스러움.
15. Deprecations·Pruning
- Spring Retry 제거 — Spring Framework core retry 사용
- JSR-352 (옛 JBatch) 표준 X
- 일부 옛 XML 네임스페이스
- Jackson 2 deprecated
migration 시 deprecation 경고 확인.
Hello Job — 5분 hands-on
이제 직접 만져 봐요.
Step 1: 프로젝트 생성
start.spring.io 에서:
- Spring Boot 3.5+
- Dependencies — Spring Batch, Spring Data JDBC, H2 Database
또는 Maven:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.0</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
Step 2: application.yml
spring:
datasource:
url: jdbc:h2:mem:batch
username: sa
password:
batch:
jdbc:
initialize-schema: always # JobRepository schema 자동 생성
job:
enabled: true # 자동 실행
Step 3: Hello Job
@Configuration
@EnableBatchProcessing
public class HelloJobConfig {
@Bean
public Job helloJob(JobRepository repo, Step helloStep) {
return new JobBuilder("helloJob", repo)
.start(helloStep)
.build();
}
@Bean
public Step helloStep(JobRepository repo, PlatformTransactionManager tx) {
return new StepBuilder("helloStep", repo)
.tasklet((contribution, chunkContext) -> {
System.out.println("Hello, Spring Batch 6!");
return RepeatStatus.FINISHED;
}, tx)
.build();
}
}
20줄 안에 완성된 Job. tasklet = 임의 작업 한 덩어리.
Step 4: Main
@SpringBootApplication
public class HelloBatchApplication {
public static void main(String[] args) {
SpringApplication.run(HelloBatchApplication.class, args);
}
}
Spring Boot 가 application context 시작 후 자동으로 helloJob 실행.
Step 5: 실행
$ mvn spring-boot:run
INFO - Starting HelloBatchApplication
INFO - JobRepository ...
INFO - Job: [SimpleJob: [name=helloJob]] launched with the following parameters: [...]
INFO - Executing step: [helloStep]
Hello, Spring Batch 6!
INFO - Step: [helloStep] executed in 12ms
INFO - Job: [SimpleJob: [name=helloJob]] completed with the following parameters
: [...] and the following status: [COMPLETED] in 45ms
COMPLETED = Job 정상 종료.
여기서 시험 함정이 하나 있어요 — 같은 JobParameters 로 두 번 실행 시 두 번째는 안 실행. 같은 JobInstance (Job + Parameters 조합 단위) 라 이미 COMPLETED 상태. 매 실행 = 다른 JobParameter (예: timestamp) 필요. 9편 Running a Job 깊이.
Chunk Job 으로 확장
Tasklet 대신 chunk-oriented 도 비슷:
@Bean
public Step chunkStep(JobRepository repo, PlatformTransactionManager tx) {
return new StepBuilder("chunkStep", repo)
.<Integer, String>chunk(3, tx)
.reader(new ListItemReader<>(List.of(1, 2, 3, 4, 5)))
.processor(item -> "Item-" + item)
.writer(chunk -> chunk.forEach(System.out::println))
.build();
}
5개 항목을 3건씩 chunk 로 처리. Read 5번 → Process 5번 → Write 2번 (3건 + 2건). 출력:
Item-1
Item-2
Item-3
Item-4
Item-5
(chunk 크기와 출력 묶음이 일치, 두 chunk 로 분리 처리)
H2 Console 로 JobRepository 보기
application.yml:
spring:
h2:
console:
enabled: true
path: /h2
http://localhost:8080/h2 접속 → BATCH_* 테이블들:
BATCH_JOB_INSTANCE— JobInstance 들BATCH_JOB_EXECUTION— JobExecution 들 (재시도 포함)BATCH_STEP_EXECUTION— StepExecution 들BATCH_JOB_EXECUTION_PARAMS— JobParametersBATCH_JOB_EXECUTION_CONTEXT·BATCH_STEP_EXECUTION_CONTEXT— ExecutionContext
운영 환경 = PostgreSQL·MySQL 의 같은 테이블 구조. 47편 Schema 깊이.
v5 → v6 마이그레이션 체크리스트
- [ ] Java 17+ (Java 21 권장 — virtual threads)
- [ ] Spring Boot 3.5+ (Spring Framework 7)
- [ ]
@EnableBatchProcessing그대로 ORDefaultBatchConfiguration으로 - [ ]
org.springframework.retryimport 제거 (v6 = Framework core 사용) - [ ] Jackson 2 → 3 (JSON reader·writer)
- [ ] JSR-352 사용 코드 제거
- [ ] Deprecated XML namespace 제거
- [ ] 새 기능 도입 검토 — CommandLineJobOperator·virtual threads·graceful shutdown·JFR
대부분 환경 = API 거의 호환. dependency 만 bump 하면 동작.
Part 1 입문 마무리
4편 (1~4):
- 1 Intro — Spring Batch 가 뭐고 언제 쓰나
- 2 Architecture — 3계층 (Application·Core·Infrastructure)
- 3 Domain Language — 11가지 핵심 어휘
- 4 v6 What's New + Hello Job — 변경점 + 5분 hands-on
이제 기본 어휘 + 어떤 도구인지 모두 손에 잡혔어요. 다음 Part 2 = 실제 Job 설정·실행 의 본격 영역.
시험 직전 한 번 더 — Spring Batch 6 + Hello Job 함정 압축 노트
- v6 = Spring Framework 7·Spring Integration 7·Spring Data 4·Java 17+
@EnableBatchProcessing기본 = ResourcelessJobRepository (학습용)@EnableJdbcJobRepository= JDBC 기반 (운영)@EnableMongoJobRepository= MongoDB 기반- 또는 base class
DefaultBatchConfiguration들 ChunkOrientedStep= chunk 가 1급 step type (v5 의 TaskletStep 위 패턴 제거)- Virtual Threads + StructuredTaskScope = concurrency 현대화
CommandLineJobOperator= CLI 표준 (--job·--stop·--restart)recover= FAILED → RECOVERED 변환 (수동 정리)- Graceful Shutdown = SIGTERM 안전 종료 (K8s 친화)
- JFR = Observability (45~46편)
- JSpecify =
@Nullable·@NonNull표준 annotation - Local Chunking = 같은 JVM 안 manager-worker (37편)
- SEDA + Spring Integration = step 들 message channel 연결
- Jackson 3 = JSON reader·writer
- Remote Step = step 자체 분산
- Lambda Style = Reader·Processor·Writer 한 줄 lambda
- Deprecation = Spring Retry 제거·JSR-352·Jackson 2
- Hello Job 패턴 =
@Configuration @EnableBatchProcessing+@Bean Job+@Bean Step - 기본 의존성 =
spring-boot-starter-batch+ H2 (학습) spring.batch.jdbc.initialize-schema: always= schema 자동spring.batch.job.enabled: true= 자동 실행- 같은 JobParameters 두 번 실행 = 두 번째 skip (같은 JobInstance COMPLETED)
- 매 실행 = 다른 JobParameter 필요 (timestamp 등)
- BATCH_* 테이블 = JobInstance·JobExecution·StepExecution·JobExecutionParams·ExecutionContext
- 마이그레이션 = Java 17+·Spring Boot 3.5+·Spring Retry 제거·Jackson 3·JSR-352 제거
공식 문서: What's new in Spring Batch 6 에서 완전한 변경 내역을 확인할 수 있어요.
시리즈 다른 편 (앞뒤 글 모음)
이전 글:
- 1편 — Spring Batch란 + 언제 쓰는가
- 2편 — Architecture (Application · Core · Infrastructure)
- 3편 — Domain Language (Job · JobInstance · Step · Item · Chunk)
다음 글: