How do I extend a named bean when using a @Qualifier
specified bean injection point?
I have project 1 consisting of 3 spring beans:
@Component("bean1")
public class Bean1 implements Bean {
}
@Component("bean2")
public class Bean2 implements Bean {
}
@Component("bean3")
public class Bean3 {
private Bean bean;
public void setBean(@Qualifier("bean1") final Bean bean) {
this.bean = bean;
}
}
This project is bundled into a jar and included as a dependency on my 2nd project:
@Component("bean1")
@Primary
public class Bean1Child extends Bean1 {
}
What I want to happen is for the bean, Bean1Child
, to be injected into Bean3
's setter method. Unfortunatly I am receiving an error.
org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'bean1' for bean class [Bean1Child] conflicts with existing, non-compatible bean definition of same name and class [Bean1]
I needed to use @Qualifier
so that Bean2
is not injected into Bean3
Using the @Primary
annotation did not help. How can I have Bean1Child
injected into Bean3
when running from my 2nd project?