티스토리 뷰
A bean with that name has already been defined ~ 관련 오류
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'sampleChunkJob', defined in class path resource [com/example/batchprocessing/SampleChunkJob.class], could not be registered. A bean with that name has already been defined in file [C:\sample-project\workspace-study\batch-processing\target\classes\com\example\batchprocessing\SampleChunkJob.class] and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
원인 : 이미 다른곳에서 문제가 되는 bean을 생성해서 생긴 문제
해결 : application.properties에 spring.main.allow-bean-definition-overriding=true 추가로 해결
(해결책이 메세지에 명확하게 나와있음..)
factory-bean reference points back to the same bean definition ~ 관련 오류
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'sampleTaskletJob' defined in class path resource [com/example/batchprocessing/SampleTaskletJob.class]: factory-bean reference points back to the same bean definition
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:721) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:681) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
원인 : Class 이름과 job 이름이 동일해서 발생한 오류
해결 : Class 이름과 job 이름을 다르게 변경해준다.
Consider marking one of the beans as @Primary ~ 관련 오류
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 1 of method sampleChunkJob in com.example.batchprocessing.SampleChunk required a single bean, but 2 were found:
- sampleChunkStep: defined by method 'sampleChunkStep' in class path resource [com/example/batchprocessing/SampleChunk.class]
- sampleTaskletStep: defined by method 'sampleTaskletStep' in class path resource [com/example/batchprocessing/SampleTasklet.class]
Action:
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 sampleChunkJob(SampleJobListener jobListener, Step step) 이런식으로 Step step 으로 모호하게 정의를 해서 발생을 했다.
해결 : Job sampleChunkJob(SampleJobListener jobListener, Step sampleChunkStep) { 이렇게 명확하게 현재 내가 작성한 step의 bean name으로 정의해준다.
EL1008E: Property or field 'jobParameters' cannot be found on object of type 오류
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'jobParameters' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public or not valid?
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:217) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:104) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:91) ~[spring-expression-5.2.2.RELEASE.jar:5.2.2.RELEASE]
원인 : jobParameter를 사용하는데 @StepScope or @JobScope를 사용하지 않아서 발생한 오류
해결 : jobParameters 사용하는 부분에 @StepScope or @JobScope 기입해준다.
No context holder available for job (or step) scope 관련 오류
Caused by: java.lang.IllegalStateException: No context holder available for job scope
at org.springframework.batch.core.scope.JobScope.getContext(JobScope.java:159) ~[spring-batch-core-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.batch.core.scope.JobScope.get(JobScope.java:92) ~[spring-batch-core-4.2.1.RELEASE.jar:4.2.1.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:356) ~[spring-beans-5.2.2.RELEASE.jar:5.2.2.RELEASE]
... 40 common frames omitted
원인 : 예를들면 reader에서 jobParameter를 사용하고 reader에 @StepScope를 붙였는데 jobParameter를 사용하지 않는 step에 @JobScope를 붙인 경우
해결 : step에 @JobScope를 제거해주고 jobParameter를 사용하는 곳에서만 @StepScope or @JobScope를 정의해준다.
끝!
'Framework > Batch' 카테고리의 다른 글
[Spring Batch] Listener Example (Springboot based) (0) | 2020.10.26 |
---|---|
[Spring Batch] Chunk Example (File to DB, Springboot based) (0) | 2020.10.23 |
Spring Batch 특정 Job만 실행하기 (2) | 2020.10.22 |
Spring Batch Tasklet Example with StepExecutionListener (0) | 2020.07.13 |
Spring Batch Chunk Example (2) - DB to DB (with MyBatisPagingItemReader, JdbcBatchItemWriter) (0) | 2020.06.07 |