Since you're seeing duplicate bean name exceptions I'll assume that you're using at least Spring Boot 2.1.0 because bean overriding is now an exception unless explicitly enabled with spring.main.allow-bean-definition-overriding = true
.
The default bean naming strategy used by Spring Boot is for imported beans to be named using the fully qualified class name and for context-scanned beans to use just the short name. See source here.
Assuming that your beans are context-scanned and are therefore clashing on the short class name and not the fully qualified name then you can tell Spring Boot to use the fully-qualified naming strategy in your main class. Just copy the few lines of source code from the ConfigurationClassPostProcessor
linked above:
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.AnnotationBeanNameGenerator;
import org.springframework.util.Assert;
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class)
.beanNameGenerator(new AnnotationBeanNameGenerator() {
@Override
protected String buildDefaultBeanName(BeanDefinition definition) {
String beanClassName = definition.getBeanClassName();
Assert.state(beanClassName != null, "No bean class name set");
return beanClassName;
}
})
.run(args);
}
This strategy will respect any bean naming directives provided by annotations that you have added to the beans.