Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overriding bean definition for bean 'X': replacing [Generic bean Y]

Tags:

spring-batch

I have the configuration like below:

batch:job id="reconciliationJob" job-repository="jobRepository" restartable="true"

and during application context startup I receive something like this in the log:

[INFO] [] [] Overriding bean definition for bean 'reconciliationJob': replacing [Generic bean: class [org.springframework.batch.core.configuration.xml.SimpleFlowFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] with [Generic bean: class [org.springframework.batch.core.configuration.xml.JobParserJobFactoryBean]; scope=; abstract=false; lazyInit=false; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null]

How can I solve this overriding problem?

like image 857
przodownikPracy Avatar asked Sep 26 '13 07:09

przodownikPracy


3 Answers

I got the same error. My problem was that I marked the class with @Service then in one of the @Configuration classes I created a @Bean out of it with the same name as the class.

like image 121
Lakatos Gyula Avatar answered Nov 03 '22 05:11

Lakatos Gyula


This happens when Spring parses the same applicationContext.xml twice.

This can happen when for example your have duplicate/overriding <context-param> imports in your WEB.xml.

To solve the issue leave only the root applicationContext.xml there and remove the children.

like image 4
Babken Vardanyan Avatar answered Nov 03 '22 06:11

Babken Vardanyan


This is not an error, is only an [INFO] and is a substitution done by Spring; you can see something similar about "step" scoped beans.
For example, if you have a bean marked as

<bean id="myBean" class="path.to.beanClass" scope="step" />

this will be replaced by a bean with name scopedTarget.myBean.
Lookup at StepScope doc and source

like image 3
Luca Basso Ricci Avatar answered Nov 03 '22 05:11

Luca Basso Ricci