로그인

Language :
제목org.springframework.batch.core.configuration.DuplicateJobException: A job configuration with this name [....] was already registered
글쓴이이지섭작성일2025-05-11수정일2025-05-13조회수886

스프링 부트에서 버전을 3.3.x 에서 3.4.x 로 올렸을 때,

아래와 같은 메시지를 접할 수 있습니다.

 

org.springframework.batch.core.configuration.DuplicateJobException: A job configuration with this name [testJob] was already registered

 

Spring Boot 3.4.x → 내부적으로 Spring Batch 5.1.x를 사용합니다.

이 버전에서 다음과 같은 변화가 발생했을 수 있습니다:

 

- Job 등록 및 JobRegistry 동작 방식 변경 가능성
 
Spring Boot 3.4에서는 Spring Batch 설정 시 JobRegistry나 JobBuilderFactory의 자동 등록 방식이 강화되었거나 중복 감지가 더 엄격해졌을 수 있습니다.
 
즉, 같은 Job 이름이 자동으로 등록된 뒤,
수동으로 또 등록하려 하면 예외가 발생하게 되었을 수 있습니다.
 
1. 직접 JobRegistry.register() 호출하지 않도록 변경해보기
 
Spring Boot 3.4.x에서는 JobRegistry 자동 등록 기능이 이미 활성화되어 있을 수 있기 때문에,
직접 등록을 제거해보시기 바랍니다.
 
@Configuration
@RequiredArgsConstructor
//@Component
@Slf4j
public class BatchConfig {
	
    private final JobRegistry jobRegistry;
	
    @Bean
    public Job testJob2(JobRepository jobRepository,PlatformTransactionManager transactionManager) throws DuplicateJobException {
       
    	Job job = new JobBuilder("testJob2",jobRepository)
               .start(testStep(jobRepository,transactionManager))
               .build();

       // 이 부분 주석 처리
       //ReferenceJobFactory factory = new ReferenceJobFactory(job);
       //jobRegistry.register(factory);
       
       return job;
    }

    @Bean
    public Step testStep(JobRepository jobRepository,PlatformTransactionManager transactionManager){
        Step step = new StepBuilder("testStep",jobRepository)
                .tasklet(testTasklet(null),transactionManager)
                .build();
        return step;
    }

    @Bean
    @StepScope
    public Tasklet testTasklet(@Value("#{jobParameters[time]}") String time) {
        return ((contribution, chunkContext) -> {

        	LocalDateTime now = LocalDateTime.now();
        	DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        	String formattedDate = now.format(formatter);
        	
        	log.info(formattedDate + " : ***** hello batch! ***** : " + time);
        	
        	return RepeatStatus.FINISHED;
        });
    }
}
 
대신 Spring Boot가 자체적으로 Job을 JobRegistry에 등록하도록 맡기면 중복 문제가 사라질 수 있습니다.

 

참조한 웹 페이지

  • ChatGPT

 

댓글

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

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