inflearn logo
강의

Khóa học

Chia sẻ kiến thức

[Giới thiệu về Spring Batch] Những kiến ​​thức cốt lõi của Spring Batch thông qua các ví dụ

Chạy một công việc hàng loạt (Lập lịch mùa xuân)

스케줄러에서 Job을 구분하지 못합니다.

Đã giải quyết

610

foodsmith96

10 câu hỏi đã được viết

0

강의 잘 들었습니다!

마지막 강의 실행 부분에서 문제가 생겼는데요
작성하신 코드와 똑같이 진행했음에도 실행 시

"Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed"

라는 에러가 나버립니다.

제 생각엔 만들어둔 Job이 7개라
어떤 Job을 실행시켜야할 지 정하지 못해 나는|
에러처럼 보입니다.

예상컨데 helloWorldJob이
HelloWorldJobConfig 클래스에서 만든 잡의
이름이라고 보는데, 저도 똑같이 했는데
왜 이런 에러가 날까요?

@Qualifier("helloWorldJob")
private final Job helloWorldJob;

를 사용해봐도 여전히 에러가 납니다.

spring-batch

Câu trả lời 1

1

mjcoding

안녕하세요 :)
스프링 컨테이너에 등록된 동일한 이름의 빈(helloWorldJob) 이 여러개 있는 것으로 생각이 돼요.
혹시 해당 프로젝트를 제 로컬에서 실행할 수 있도록, 깃헙링크를 받을 수 있을까요?

0

foodsmith96

네! 깃헙은 아래 링크입니다.
https://github.com/jeongdonguk96/batch

에러메시지를 더 자세하게 드렸어야 했는데
helloWorldJob 이름으로 빈 등록이 여러 개 된 것은 아니라고 보여집니다!

Parameter 1 of constructor in com.io.batch.scheduler.CustomScheduler required a single bean, but 7 were found:

- conditionalStepJob: defined by method 'conditionalStepJob' in class path resource [com/io/batch/job/conditionalstep/ConditionalStepJobConfig.class]

- trMigrationJob: defined by method 'trMigrationJob' in class path resource [com/io/batch/job/dbreadwrite/TrMigrationConfig.class]

- fileReadWriteJob: defined by method 'fileReadWriteJob' in class path resource [com/io/batch/job/filereadwrite/FileReadWriteConfig.class]

- helloWorld: defined by method 'helloWorld' in class path resource [com/io/batch/job/hellowolrd/HelloWorldJobConfig.class]

- jobListenerJob: defined by method 'jobListenerJob' in class path resource [com/io/batch/job/joblistener/JobListenerConfig.class]

- multiStepJob: defined by method 'multiStepJob' in class path resource [com/io/batch/job/multistep/MultiStepJobConfig.class]

- validatedParamJob: defined by method 'validatedParamJob' in class path resource [com/io/batch/job/validatedparam/ValidatedParamJobConfig.class]

감사합니다~

0

mjcoding

말씀 처럼 여러개의 helloWorldJob 빈이 등록이 되어 있는 것이 아닌, helloWorldJob 빈이 등록이 되어 있지 않아서 발생하는 에러입니다 :)
에러 내용을 보시게 되면 helloWorldJob 빈이 등록 되어 있지 않은 모습인데요. helloWorldJob 대신 helloWorld[0] 이름으로 빈이 등록 되어 있습니다. 메서드 이름을 helloWorld[0] 대신에, helloWorldJob 으로 변경을 필요로 해요. 이렇게 등록된 빈을 주입 받으실 때는 helloWorldJobConfig[1] 이름 대신, helloWorldJob 으로 주입을 받으셔야 되겠습니다.
(helloWorldJobConfig 변수[1] 이름을, helloWorldJob으로 변경을 해주시면 되겠습니다.)

bean 어노테이션을 활용한 빈 등록은, 메서드 이름이 빈으로 등록이 돼요.
스프링 배치 강의다 보니, 스프링 프레임워크 관련 설명을 자세히 드리지 못했던 점 죄송합니다 ㅠ.ㅠ
지금 경우는 빈이 등록이 안되어 있는 문제는 실무에서도 종종 만날 수 있는 문제이니 좋은 학습이 되셨으리라 생각이 되겠습니다 :)

[0]
https://github.com/jeongdonguk96/batch/blob/master/src/main/java/com/io/batch/job/hellowolrd/HelloWorldJobConfig.java#L31
[1]
https://github.com/jeongdonguk96/batch/blob/master/src/main/java/com/io/batch/scheduler/CustomScheduler.java#L22

배치 실행시 파라미터 (파일 이름)받기 및 (csv) 검증 5.0버전 공유

1

51

1

질문x 1강 일단 실행 코드부분 5.0에 맞춰 수정

1

38

1

spring batch 5.x 버전 설정

1

141

2

Spring Batch 5버전의 경우 실행법 공유

0

166

1

질문입니다.

0

108

1

소스 다운 받을 수 없는건가요?

0

120

1

학습에 사용하는 문서 자료 같은 건 없나요?

0

123

1

spring batch 5버전 소스는 없나요

0

439

1

질문드립니다.

0

340

1

@Configuration 어노테이션 관련 질문있습니다.

0

277

1

다중 Job 구동시 질문 있습니다!!

0

318

1

설정 관련 문의

1

303

1

다중DB 접속 설정 에러

0

960

1

조건별 분기 처리시 질문있습니다

0

353

1

Spring Batch 테이블이 생성되질 않습니다!!!!!

0

1708

2

db이관시 sql 스크립트 데이터 복붙하라고 하시는데 파일은 어디에 있나요 ?

0

493

1

Spring Batch5로 강의내용 최신화 업데이트될 가능성이 있을까요?

0

873

1

reader, writer, processor에서 적용

0

492

1

똑같이 실행하는데 출력이 안돼요

0

1023

2

빌드가 실패해요 ㅠㅠ

1

3210

1

Chunk size에 대해

0

3179

1

Run / Debug 관련 질문드립니다..!

1

916

2

완강했습니다! 마지막 질문 드리고 싶습니다.

0

424

1

여러개의 step 구동 질문

0

398

1