|
34 | 34 | import org.springframework.beans.factory.BeanFactory;
|
35 | 35 | import org.springframework.beans.factory.FactoryBean;
|
36 | 36 | import org.springframework.beans.factory.ObjectFactory;
|
| 37 | +import org.springframework.beans.factory.UnsatisfiedDependencyException; |
37 | 38 | import org.springframework.beans.factory.config.BeanDefinition;
|
38 | 39 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
39 | 40 | import org.springframework.beans.factory.config.TypedStringValue;
|
@@ -549,6 +550,23 @@ public void testConstructorResourceInjectionWithMultipleCandidates() {
|
549 | 550 | bf.destroySingletons();
|
550 | 551 | }
|
551 | 552 |
|
| 553 | + @Test |
| 554 | + public void testConstructorResourceInjectionWithNoCandidatesAndNoFallback() { |
| 555 | + DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); |
| 556 | + AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); |
| 557 | + bpp.setBeanFactory(bf); |
| 558 | + bf.addBeanPostProcessor(bpp); |
| 559 | + bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ConstructorWithoutFallbackBean.class)); |
| 560 | + |
| 561 | + try { |
| 562 | + bf.getBean("annotatedBean"); |
| 563 | + fail("Should have thrown UnsatisfiedDependencyException"); |
| 564 | + } |
| 565 | + catch (UnsatisfiedDependencyException ex) { |
| 566 | + // expected |
| 567 | + } |
| 568 | + } |
| 569 | + |
552 | 570 | @Test
|
553 | 571 | public void testConstructorResourceInjectionWithMultipleCandidatesAsCollection() {
|
554 | 572 | DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
@@ -2025,6 +2043,21 @@ public NestedTestBean[] getNestedTestBeans() {
|
2025 | 2043 | }
|
2026 | 2044 |
|
2027 | 2045 |
|
| 2046 | + public static class ConstructorWithoutFallbackBean { |
| 2047 | + |
| 2048 | + protected ITestBean testBean3; |
| 2049 | + |
| 2050 | + @Autowired(required = false) |
| 2051 | + public ConstructorWithoutFallbackBean(ITestBean testBean3) { |
| 2052 | + this.testBean3 = testBean3; |
| 2053 | + } |
| 2054 | + |
| 2055 | + public ITestBean getTestBean3() { |
| 2056 | + return this.testBean3; |
| 2057 | + } |
| 2058 | + } |
| 2059 | + |
| 2060 | + |
2028 | 2061 | public static class ConstructorsCollectionResourceInjectionBean {
|
2029 | 2062 |
|
2030 | 2063 | protected ITestBean testBean3;
|
@@ -2090,7 +2123,6 @@ public static class MapFieldInjectionBean {
|
2090 | 2123 | @Autowired
|
2091 | 2124 | private Map<String, TestBean> testBeanMap;
|
2092 | 2125 |
|
2093 |
| - |
2094 | 2126 | public Map<String, TestBean> getTestBeanMap() {
|
2095 | 2127 | return this.testBeanMap;
|
2096 | 2128 | }
|
|
0 commit comments