I am trying to introduce a special Generic bean into a common subtype, but Spring cannot resolve the dependency. By removing the type from the bean, everything works as expected. Here is an example:
public class AbstractFrom{ // ... } public class EmployyForm extends AbstractFrom{ // ... } public class CompanyForm extends AbstractFrom{ // ... } abstract class AbstractBean<T extends AbstractFrom>{ public abstract void calculate(T form); } @Component public CompanyBean extends AbstractBean<CompanyForm>{ public void calculate(CompanyForm form){ // specific impl } } @Component public EmployeeBean extends AbstractBean<EmployyForm>{ public void calculate(EmployyForm form){ // specific impl } }
Here is the target class:
@Service public BaseService{ @Autowire public AbstractBean<AbstractFrom> baseBean; // <- NoSuchBeanDefinitionException // @Autowire // public AbstractBean baseBean; <- Injection works as is expected }
Active profile dependencies are initialized only by CompanyBean
or EmployeeBean
, and not both. I also tried setting the same name using beans annotation and us @Qualifier
.
Is there any way to use this bean using diamond syntax? Can Spring resolve this dependency? Using Spring 4.2.x.
Edit: When using Spring 4.3 should be possible. See JΓΌrgen Hover's discussion
source share