|
|
|
@ -2163,9 +2163,39 @@ class DefaultListableBeanFactoryTests { |
|
|
|
lbf.registerBeanDefinition("test", bd); |
|
|
|
lbf.registerBeanDefinition("test", bd); |
|
|
|
lbf.registerBeanDefinition("spouse", bd2); |
|
|
|
lbf.registerBeanDefinition("spouse", bd2); |
|
|
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(UnsatisfiedDependencyException.class).isThrownBy(() -> |
|
|
|
assertThatExceptionOfType(UnsatisfiedDependencyException.class) |
|
|
|
lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true)) |
|
|
|
.isThrownBy(() -> lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true)) |
|
|
|
.withCauseExactlyInstanceOf(NoUniqueBeanDefinitionException.class); |
|
|
|
.withCauseExactlyInstanceOf(NoUniqueBeanDefinitionException.class); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void autowireBeanByTypeWithTwoPrimaryCandidatesInOneAncestor() { |
|
|
|
|
|
|
|
DefaultListableBeanFactory parent = new DefaultListableBeanFactory(); |
|
|
|
|
|
|
|
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); |
|
|
|
|
|
|
|
bd.setPrimary(true); |
|
|
|
|
|
|
|
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class); |
|
|
|
|
|
|
|
bd2.setPrimary(true); |
|
|
|
|
|
|
|
parent.registerBeanDefinition("test", bd); |
|
|
|
|
|
|
|
parent.registerBeanDefinition("spouse", bd2); |
|
|
|
|
|
|
|
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(parent); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(UnsatisfiedDependencyException.class) |
|
|
|
|
|
|
|
.isThrownBy(() -> lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true)) |
|
|
|
|
|
|
|
.withCauseExactlyInstanceOf(NoUniqueBeanDefinitionException.class); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void autowireBeanByTypeWithTwoPrimaryFactoryBeans(){ |
|
|
|
|
|
|
|
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); |
|
|
|
|
|
|
|
RootBeanDefinition bd1 = new RootBeanDefinition(LazyInitFactory.class); |
|
|
|
|
|
|
|
RootBeanDefinition bd2 = new RootBeanDefinition(LazyInitFactory.class); |
|
|
|
|
|
|
|
bd1.setPrimary(true); |
|
|
|
|
|
|
|
bd2.setPrimary(true); |
|
|
|
|
|
|
|
lbf.registerBeanDefinition("bd1", bd1); |
|
|
|
|
|
|
|
lbf.registerBeanDefinition("bd2", bd2); |
|
|
|
|
|
|
|
assertThatExceptionOfType(UnsatisfiedDependencyException.class) |
|
|
|
|
|
|
|
.isThrownBy(() -> lbf.autowire(FactoryBeanDependentBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true)) |
|
|
|
|
|
|
|
.withCauseExactlyInstanceOf(NoUniqueBeanDefinitionException.class); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
|