@@ -2163,9 +2163,39 @@ void autowireBeanByTypeWithTwoPrimaryCandidates() {
2163
2163
lbf .registerBeanDefinition ("test" , bd );
2164
2164
lbf .registerBeanDefinition ("spouse" , bd2 );
2165
2165
2166
- assertThatExceptionOfType (UnsatisfiedDependencyException .class ).isThrownBy (() ->
2167
- lbf .autowire (DependenciesBean .class , AutowireCapableBeanFactory .AUTOWIRE_BY_TYPE , true ))
2168
- .withCauseExactlyInstanceOf (NoUniqueBeanDefinitionException .class );
2166
+ assertThatExceptionOfType (UnsatisfiedDependencyException .class )
2167
+ .isThrownBy (() -> lbf .autowire (DependenciesBean .class , AutowireCapableBeanFactory .AUTOWIRE_BY_TYPE , true ))
2168
+ .withCauseExactlyInstanceOf (NoUniqueBeanDefinitionException .class );
2169
+ }
2170
+
2171
+ @ Test
2172
+ void autowireBeanByTypeWithTwoPrimaryCandidatesInOneAncestor () {
2173
+ DefaultListableBeanFactory parent = new DefaultListableBeanFactory ();
2174
+ RootBeanDefinition bd = new RootBeanDefinition (TestBean .class );
2175
+ bd .setPrimary (true );
2176
+ RootBeanDefinition bd2 = new RootBeanDefinition (TestBean .class );
2177
+ bd2 .setPrimary (true );
2178
+ parent .registerBeanDefinition ("test" , bd );
2179
+ parent .registerBeanDefinition ("spouse" , bd2 );
2180
+ DefaultListableBeanFactory lbf = new DefaultListableBeanFactory (parent );
2181
+
2182
+ assertThatExceptionOfType (UnsatisfiedDependencyException .class )
2183
+ .isThrownBy (() -> lbf .autowire (DependenciesBean .class , AutowireCapableBeanFactory .AUTOWIRE_BY_TYPE , true ))
2184
+ .withCauseExactlyInstanceOf (NoUniqueBeanDefinitionException .class );
2185
+ }
2186
+
2187
+ @ Test
2188
+ void autowireBeanByTypeWithTwoPrimaryFactoryBeans (){
2189
+ DefaultListableBeanFactory lbf = new DefaultListableBeanFactory ();
2190
+ RootBeanDefinition bd1 = new RootBeanDefinition (LazyInitFactory .class );
2191
+ RootBeanDefinition bd2 = new RootBeanDefinition (LazyInitFactory .class );
2192
+ bd1 .setPrimary (true );
2193
+ bd2 .setPrimary (true );
2194
+ lbf .registerBeanDefinition ("bd1" , bd1 );
2195
+ lbf .registerBeanDefinition ("bd2" , bd2 );
2196
+ assertThatExceptionOfType (UnsatisfiedDependencyException .class )
2197
+ .isThrownBy (() -> lbf .autowire (FactoryBeanDependentBean .class , AutowireCapableBeanFactory .AUTOWIRE_BY_TYPE , true ))
2198
+ .withCauseExactlyInstanceOf (NoUniqueBeanDefinitionException .class );
2169
2199
}
2170
2200
2171
2201
@ Test
0 commit comments