|
30 | 30 | import org.springframework.beans.factory.BeanFactory;
|
31 | 31 | import org.springframework.beans.factory.FactoryBean;
|
32 | 32 | import org.springframework.beans.factory.ObjectFactory;
|
| 33 | +import org.springframework.beans.factory.UnsatisfiedDependencyException; |
33 | 34 | import org.springframework.beans.factory.config.BeanDefinition;
|
34 | 35 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
35 | 36 | import org.springframework.beans.factory.support.AutowireCandidateQualifier;
|
@@ -395,6 +396,23 @@ public void testConstructorResourceInjectionWithMultipleCandidates() {
|
395 | 396 | bf.destroySingletons();
|
396 | 397 | }
|
397 | 398 |
|
| 399 | + @Test |
| 400 | + public void testConstructorResourceInjectionWithNoCandidatesAndNoFallback() { |
| 401 | + DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); |
| 402 | + AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); |
| 403 | + bpp.setBeanFactory(bf); |
| 404 | + bf.addBeanPostProcessor(bpp); |
| 405 | + bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ConstructorWithoutFallbackBean.class)); |
| 406 | + |
| 407 | + try { |
| 408 | + bf.getBean("annotatedBean"); |
| 409 | + fail("Should have thrown UnsatisfiedDependencyException"); |
| 410 | + } |
| 411 | + catch (UnsatisfiedDependencyException ex) { |
| 412 | + // expected |
| 413 | + } |
| 414 | + } |
| 415 | + |
398 | 416 | @Test
|
399 | 417 | public void testConstructorResourceInjectionWithMultipleCandidatesAsCollection() {
|
400 | 418 | DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
@@ -1256,6 +1274,21 @@ public NestedTestBean[] getNestedTestBeans() {
|
1256 | 1274 | }
|
1257 | 1275 |
|
1258 | 1276 |
|
| 1277 | + public static class ConstructorWithoutFallbackBean { |
| 1278 | + |
| 1279 | + protected ITestBean testBean3; |
| 1280 | + |
| 1281 | + @Autowired(required = false) |
| 1282 | + public ConstructorWithoutFallbackBean(ITestBean testBean3) { |
| 1283 | + this.testBean3 = testBean3; |
| 1284 | + } |
| 1285 | + |
| 1286 | + public ITestBean getTestBean3() { |
| 1287 | + return this.testBean3; |
| 1288 | + } |
| 1289 | + } |
| 1290 | + |
| 1291 | + |
1259 | 1292 | public static class ConstructorsCollectionResourceInjectionBean {
|
1260 | 1293 |
|
1261 | 1294 | protected ITestBean testBean3;
|
@@ -1321,7 +1354,6 @@ public static class MapFieldInjectionBean {
|
1321 | 1354 | @Autowired
|
1322 | 1355 | private Map<String, TestBean> testBeanMap;
|
1323 | 1356 |
|
1324 |
| - |
1325 | 1357 | public Map<String, TestBean> getTestBeanMap() {
|
1326 | 1358 | return this.testBeanMap;
|
1327 | 1359 | }
|
|
0 commit comments