Skip to content

fix(batch): EgovPartitionFlatFileItemWriter의 Spring Batch 5 계약 복구 - #291

Open
ParkJunGyu26 wants to merge 1 commit into
eGovFramework:mainfrom
ParkJunGyu26:fix/batch-partition-writer-contract
Open

fix(batch): EgovPartitionFlatFileItemWriter의 Spring Batch 5 계약 복구#291
ParkJunGyu26 wants to merge 1 commit into
eGovFramework:mainfrom
ParkJunGyu26:fix/batch-partition-writer-contract

Conversation

@ParkJunGyu26

@ParkJunGyu26 ParkJunGyu26 commented Jul 29, 2026

Copy link
Copy Markdown

수정 사유 Reason for modification

  • 버그수정 Bug fixes
  • 기능개선 Enhancements
  • 기능추가 Adding features
  • 기타 Others

수정된 소스 내용 Modified source

공식 문서 참고

현재 Batch 모듈의 Spring Batch 의존성은 5.2.3입니다.
Spring Batch 5.2.3 공식 API 문서 기준으로 ItemWriterwrite 메서드는 List가 아니라 Chunk<? extends T>를 인자로 받습니다.

Spring Batch ItemWriter write Chunk API

또한 ResourceAwareItemWriterItemStreamWritableResource에 출력하는 ItemStreamWriter 계약을 제공하며, setResource(WritableResource resource) 메서드를 정의합니다.

Spring Batch ResourceAwareItemWriterItemStream setResource API

따라서 본 PR은 EgovPartitionFlatFileItemWriter가 Spring Batch 5의 writer/resource 계약에 맞게 실제 리소스를 설정하고, Chunk 기반 쓰기 호출을 기존 파일 쓰기 로직으로 위임하도록 수정한 것입니다.

AS-IS

Spring Batch 5에서 ItemWriter#write(List)ItemWriter#write(Chunk)로 변경되었으나,
EgovPartitionFlatFileItemWriter의 Spring Batch 5 인터페이스 구현이 비어 있습니다.

@Override
public void setResource(WritableResource resource) {
}

@Override
public void write(Chunk<? extends T> chunk) {
}

이로 인해 다음 문제가 발생합니다.

  • WritableResource 인터페이스를 통해 출력 리소스를 설정하면 내부 resourcenull로 남아
    open()에서 The resource must be set 예외가 발생합니다.
  • Spring Batch의 SimpleChunkProcessor가 호출하는 write(Chunk)가 아무 작업도 하지 않아
    Step이 전달한 항목이 파일에 기록되지 않습니다.
  • 기존 write(List)의 실제 파일 쓰기 로직은 남아 있지만 Spring Batch 5의 호출 경로와
    연결되지 않습니다.

Spring Batch 5 마이그레이션 가이드:
https://github.com/spring-projects/spring-batch/wiki/Spring-Batch-5.0-Migration-Guide

TO-BE

  • setResource(WritableResource)를 기존 setResource(Resource)에 위임합니다.
  • write(Chunk)와 기존 write(List)가 동일한 private doWrite(List) 구현을 사용합니다.
  • 두 public 쓰기 진입점의 기존 동기화 특성을 유지합니다.
  • 기존 파일 인코딩, header/footer, transactional buffer, restart 상태 로직은 변경하지 않습니다.
@Override
public void setResource(WritableResource resource) {
    setResource((Resource) resource);
}

@Override
public synchronized void write(Chunk<? extends T> chunk) {
    doWrite(chunk.getItems());
}

영향 범위 및 호환성

  • 기존 write(List) 공개 메서드를 유지합니다.
  • 기존 public 메서드의 checked exception 선언을 변경하지 않습니다.
  • Maven 의존성과 설정을 변경하지 않습니다.
  • Chunk 및 List 쓰기 진입점은 동일한 객체 monitor로 동기화됩니다.
  • 운영 코드 변경은 EgovPartitionFlatFileItemWriter에 한정됩니다.

JUnit 테스트 JUnit tests

  • JUnit 테스트 JUnit tests
  • 수동 테스트 Manual testing

수정 전 재현

origin/main에 동일한 회귀 테스트를 실행한 결과입니다.

Tests run: 2, Failures: 1, Errors: 1, Skipped: 0

setsWritableResource:
IllegalArgumentException: The resource must be set

writesChunk:
expected: "first\nsecond\n"
actual:   ""

수정 후 회귀 테스트

Tests run: 2, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

Batch 모듈 전체 검증

mvn -B -Dfile.encoding=UTF-8 -Duser.timezone=Asia/Seoul verify

Tests run: 63, Failures: 0, Errors: 0, Skipped: 0
BUILD SUCCESS

JAR, sources JAR 및 Javadoc JAR 생성도 완료되었습니다.

테스트 브라우저 Test Browser

  • Chrome
  • Firefox
  • Edge
  • Safari
  • Opera
  • Internet Explorer
  • 기타 Others: 브라우저 비대상 Java 라이브러리

테스트 스크린샷 또는 캡처 영상 Test screenshots or captured video

AS-IS

Spring Batch 5 인터페이스 경로에서 동일한 회귀 테스트 2개가 실패합니다.

as-is

TO-BE

동일한 Java 17 환경에서 같은 회귀 테스트 2개가 모두 통과합니다.

to-be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant