로그인

Language :
제목스프링 부트 4.0.1 에서 스프링 배치의 라이브러리가 변경되었다.
글쓴이이지섭작성일2026-01-08수정일2026-01-09조회수23
스프링 부트 4.0.1 에서 스프링 배치의 라이브러리가 변경되었다.
 
스프링 부트 4.0.1 에서 스프링 배치 라이브러리는 다음과 같이 버전이 변경되었다.
 
org\springframework\batch\spring-batch-core\6.0.1\spring-batch-core-6.0.1.jar
org\springframework\batch\spring-batch-infrastructure\6.0.1\spring-batch-infrastructure-6.0.1.jar
 
이 두 파일의 Java 컴파일러 지원 버전은 17 이상이다.
 
주요 클래스를 확인해보면 아래과 같이 변경이 되었다.
배치를 도입하는 방식에도 변화가 생겼다.
 
전부 기재한 것은 아니고,
주요 클래스 일부만 기재한 것이다.
 
[ spring-batch-core-6.0.1.jar ]

3.x.x : org.springframework.batch.core.Job
4.0.1 : org.springframework.batch.core.job.Job

3.x.x : org.springframework.batch.core.Step
4.0.1 : org.springframework.batch.core.step.Step

3.x.x : org.springframework.batch.core.JobParametersInvalidException
4.0.1 : org.springframework.batch.core.job.parameters.InvalidJobParametersException

3.x.x : org.springframework.batch.core.JobParametersBuilder
4.0.1 : org.springframework.batch.core.job.parameters.JobParametersBuilder

3.x.x : org.springframework.batch.core.repository.JobExecutionAlreadyRunningException
4.0.1 : org.springframework.batch.core.launch.JobExecutionAlreadyRunningException

3.x.x : org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException
4.0.1 : org.springframework.batch.core.launch.JobInstanceAlreadyCompleteException

3.x.x : org.springframework.batch.core.repository.JobRestartException
4.0.1 : org.springframework.batch.core.launch.JobRestartException

[ spring-batch-infrastructure-6.0.1.jar ]

3.x.x : org.springframework.batch.repeat.RepeatStatus
4.0.1 : org.springframework.batch.infrastructure.repeat.RepeatStatus
 
스프링 배치의 버전만 4.0.1로 업그레이드 하면
위와 같이 배치의 클래스 정보가 변경되었기 때문에 에러가 발생한다.
 
 
스프링 부트 4.0.1 에서, jobLauncher 가 deprecated 인데,
jobLauncher.run() 하는 방법은 다음과 같습니다.
 
스프링 부트 4.0.1 에서 JobLauncher 자체는 여전히 사용 가능하나, 
기존에 주로 사용되던 구현체나 특정 연동 방식이 변경되었을 가능성이 큽니다. 
특히 JobLauncher를 직접 사용하기보다는 더 추상화된 인터페이스를 사용하는 것이 권장됩니다. 
 
1. JobOperator 사용 (권장)
최근 스프링 배치 버전에서는 JobLauncher 대신 JobOperator를 사용하여 작업을 시작하거나 중지하는 방식이 권장됩니다. 
JobOperator는 작업 이름과 파라미터를 문자열 형태로 전달받아 실행할 수 있어 더 유연합니다. 
 
@Autowired
private JobOperator jobOperator;

public void runJob() throws Exception {
    // jobName, jobParameters(문자열 형태)를 인자로 실행
    Long executionId = jobOperator.start("myJobName", "parameter1=value1,time=" + System.currentTimeMillis());
}
 
 
스프링부트 + Mybatis 프로젝트에서 @Mapper 클래스가 bean 등록이 되지 않는 문제가 발생할 수 있는데,
 
이 경우는 org.mybatis.spring.boot.mybatis-spring-boot-starter 의존성 버전을 4.0.1 로 맞춰주면 해결이 됩니다.
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>4.0.1</version>
</dependency>
 
 
참고로, @Scheduled 어노테이션을 사용하기 위해 Application Class에 @EnableScheduling을 추가한다.
package spring_boot_batch;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;

@EnableScheduling
@SpringBootApplication
public class SpringBootBatchApplication {
	public static void main(String[] args) {
		SpringApplication.run(SpringBootBatchApplication.class, args);
	}
}
 
스프링 부트 4.0.1 에서의 배치 프로그램을 본 게시글에 첨부파일로 등록을 하였습니다.
참조해 볼 수 있겠습니다.
 
 
[ 참조한 레퍼런스 ]
 
첨부파일
BatchConfig.java (3,008 byte)
BatchScheduler.java (1,575 byte)
pom.xml (2,746 byte)

댓글

이름               비밀번호 
내용
비밀번호를 확인합니다.

댓글 등록시 입력한 비밀번호를 입력해주시기 바랍니다.


개인정보 처리방침