'Spring Boot @Configuration bean name conflicts
I have a project with lot of small libraries that define beans with @Configuration classes (Spring Integration and Spring Batch stuff) and I often encounter problems because both libraries have a bean with the same name.
It is possible to either:
- Apply a prefix to all the beans of a configuration classes
- Force the application to crash at startup if two beans exists with the same name
- Use another solution that would fix it without a redesign of the application
Solution 1:[1]
I understand you mean that you have two beans called the same with the @Configuration annotation, this collides and does not work with the following error:
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.lapeira.formacion.CasoFinalApplication]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'configuracion' for bean class [com.lapeira.formacion.seguridad.Configuracion] conflicts with existing, non-compatible bean definition of same name and class [com.lapeira.formacion.batch.Configuracion]
Just rename one of the two classes and it should work.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Raul Lapeira Herrero |
