맨땅에 헤딩하는 개바른자

Spring Batch 구동안되는 문제 유형 본문

개발막힘 해결 TIP

Spring Batch 구동안되는 문제 유형

앵낄낄 2022. 4. 14. 15:21
반응형

https://khj93.tistory.com/entry/Spring-Batch란-이해하고-사용하기

  1. config를 추가하고 기동을 해보았다
  2. 아래와 같은 에러가...
***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in com.hanatour.dcr.batch.config.JobConfig required a bean of type 'org.springframework.batch.core.configuration.annotation.JobBuilderFactory' that could not be found.

Action:

Consider defining a bean of type 'org.springframework.batch.core.configuration.annotation.JobBuilderFactory' in your configuration.

Disconnected from the target VM, address: '127.0.0.1:54701', transport: 'socket'

Process finished with exit code 0

 

[해결]

main 메소드가 있는 파일에 아래 설정을 추가

@EnableBatchProcessing

 

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를 정의해준다.

출처:

https://oingdaddy.tistory.com/178

[SI Supply Depot]

반응형