Annotation-specified bean name conflicts with existing, non-compatible bean def Annotation-specified bean name conflicts with existing, non-compatible bean def spring spring

Annotation-specified bean name conflicts with existing, non-compatible bean def


I had a similar issue with Spring 4.x using @RestController. Two different packages had a class with the same name...

package com.x.catalog@RestControllerpublic class TextureController {...package com.x.cms@RestControllerpublic class TextureController {...

The fix was easy...

package com.x.catalog@RestController("CatalogTextureController")public class TextureController {...package com.x.cms@RestController("CMSTextureController")public class TextureController {...

The problem seems to be that the annotation gets autowired and takes the class name by default. Giving it an explicit name in the @RestController annotation allows you to keep the class names.


In an XML file, there is a sequence of declarations, and you may override a previous definition with a newer one. When you use annotations, there is no notion of before or after. All the beans are at the same level. You defined two beans with the same name, and Spring doesn't know which one it should choose.

Give them a different name (staticConverterDAO, inMemoryConverterDAO for example), create an alias in the Spring XML file (theConverterDAO for example), and use this alias when injecting the converter:

@Autowired @Qualifier("theConverterDAO")


I had a similar problem, with two jar libraries (app1 and app2) in one project. The bean "BeanName" is defined in app1 and is extended in app2 and the bean redefined with the same name.

In app1:

package com.foo.app1.pkg1;@Component("BeanName")public class Class1 { ... }

In app2:

package com.foo.app2.pkg2;@Component("BeanName")public class Class2 extends Class1 { ... }

This causes the ConflictingBeanDefinitionException exception in the loading of the applicationContext due to the same component bean name.

To solve this problem, in the Spring configuration file applicationContext.xml:

    <context:component-scan base-package="com.foo.app2.pkg2"/>    <context:component-scan base-package="com.foo.app1.pkg1">        <context:exclude-filter type="assignable" expression="com.foo.app1.pkg1.Class1"/>    </context:component-scan>

So the Class1 is excluded to be automatically component-scanned and assigned to a bean, avoiding the name conflict.