일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
- 스프링 배치
- 스프링 시큐리티
- virtualization
- spring batch
- 스프링
- vm
- 도커
- Container
- HTTP
- computer science
- ORM
- CI/CD
- 데이터베이스
- CS
- JPA
- 배포
- 백엔드
- Spring
- mysql
- spring cloud
- 자바
- spring boot
- 컨테이너
- 가상화
- web server
- Spring Security
- 영속성 컨텍스트
- 스프링 부트
- 웹 서버
- Java
- Today
- Total
개발 일기
[Spring Batch] Spring Batch5 이전 버전(4)과의 차이점 본문
Spring Boot 3.x 버전이 등장하며 Spring Batch 버전 또한 익히 알려져있는 4버전이 아닌 5버전을 활용하게 되었다.
Spring Batch4와 5는 차이가 커서 하나씩 정리해보고자 한다.
1. 다양한 JobParameter Type
4.x 버전까지는 4개의 Type(Long, Double, String, Date)만을 지원했지만 5부터는 JobParameter를 커스텀해서 사용할 수 있다.
원래는 제너릭을 지원하지 않았는데 제너릭 타입을 지원하는 것을 확인할 수있다.
2. Deprecated된 StepBuilderFactory와 JobBuilderFactory
Implicit configuration로 인해 StepBuilderFactory와 JobBuilderFactory가 Deprecated됐다.
JobBuilderFactory는 @EnableBatchProcessing과 함께 사용할 때 자동으로 JobRepository를 생성하여 주입된다.
@EnableBatchProcessing
public class MyJobConfig {
@Autowired
private JobBuilderFactory jobBuilderFactory;
@Bean
public Job job(Step step) {
return this.jobBuilderFactory.get("myJob")
.start(step)
.build();
}
}
이전 방식에서는 JobBuilderFactory와 StepBuilderFactory를 사용하여 Job과 Step을 생성했지만, 이 과정에서 JobRepository와 TransactionManager가 자동으로 설정되어 명시적이지 않아 모호한 부분이 있었다.
이를 개선하기 위해, JobBuilderFactory와 StepBuilderFactory 사용을 지양하고, JobRepository와 TransactionManager를 직접 명시적으로 주입해주는 방식으로 코드를 작성하도록 유도했다. 이는 의존성을 명확하게 드러내기 위함이며, 이를 위해 이전의 JobBuilderFactory와 StepBuilderFactory는 Deprecated(사용 중단 권고)되었다.
@EnableBatchProcessing
public class MyJobConfig {
// Job 구성
@Bean
public Job job(JobRepository jobRepository, Step step) {
return new JobBuilder("myJob")
.repository(jobRepository)
.start(step)
.build();
}
// Step 구성
@Bean
public Step findKeywordListStep() {
return new StepBuilder(FIND_KEYWORD_LIST_STEP_NAME, jobRepository)
.tasklet(findKeywordListTasklet) // 주입된 Tasklet 사용
.transactionManager(transactionManager) // 트랜잭션 매니저 설정
.build();
}
}
https://github.com/spring-projects/spring-batch/issues/4188
Deprecate Job/Step builder factories · Issue #4188 · spring-projects/spring-batch
JobBuilderFactory was reported to be of no real added value compared to JobBuilder. In fact, it only sets a single property on the builder it creates, which is the job repository. While this is not...
github.com
3. DefaultBatchConfiguration 클래스가 추가
위에서 처럼 @EnableBatchProcessing가 JobRepository, JobLauncher, StepScope, JobScope 등의 Bean을 등록해주는 것을 대체 해줄 Configuration class가 추가됐다.
@Configuration
class MyJobConfiguration extends DefaultBatchConfiguration {
@Bean
public Job job(JobRepository jobRepository) {
return new JobBuilder("myJob", jobRepository)
.build();
}
@Override
protected Charset getCharset() {
return StandardCharsets.ISO_8859_1;
}
}
또한 DefaultBatchConfiguration에서는 getDataSource, getTransactionManager, getCharset 등의 다양한 protected method 들을 제공하고 있으며, 자식 클래스에서 이를 Override 하여 간편하게 Batch 설정을 커스터마이즈 할 수 있게 됐다.
‼️ @EnableBatchProcessing과 DefaultBatchConfiguration를 함께 사용 X
4. GraalVM native 지원
GraalVM을 활용해 Spring Batch 애플리케이션을 네이티브로 컴파일할 수 있게 되면서, 성능이 크게 향상됐다. 이를 위해 Ahead-Of-Time (AOT) 컴파일 과정과 런타임 힌트가 제공되어, 실행 속도가 빨라지고 메모리 사용량이 줄어드는 등의 이점이 있다.
'Back-End > Spring' 카테고리의 다른 글
[Spring Boot] @ResponseBody와 ResponseEntity 비교 (2) | 2024.09.19 |
---|---|
[Spring Batch] Spring Batch에서 Tasklet 방식과 Chunk 방식 비교 (0) | 2024.09.19 |
[Spring Batch] 배치 처리와 스프링 배치 그리고 스케줄러 (2) | 2024.09.17 |
[Spring Boot] 예외처리 및 @RestControllerAdvice & @ExceptionHandler (0) | 2024.09.15 |
[Spring Boot] 서비스 운영 관점에서 FK(외래키) 설정이 꼭 필요할까? (3) | 2024.08.28 |