|
35 | 35 | import org.springframework.beans.factory.BeanFactory;
|
36 | 36 | import org.springframework.beans.factory.FactoryBean;
|
37 | 37 | import org.springframework.beans.factory.ObjectFactory;
|
| 38 | +import org.springframework.beans.factory.UnsatisfiedDependencyException; |
38 | 39 | import org.springframework.beans.factory.config.BeanDefinition;
|
39 | 40 | import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
40 | 41 | import org.springframework.beans.factory.config.TypedStringValue;
|
|
52 | 53 | import org.springframework.util.SerializationTestUtils;
|
53 | 54 |
|
54 | 55 | import static org.junit.Assert.*;
|
55 |
| -import static org.mockito.Mockito.*; |
56 | 56 |
|
57 | 57 | /**
|
58 | 58 | * @author Juergen Hoeller
|
@@ -552,6 +552,23 @@ public void testConstructorResourceInjectionWithMultipleCandidates() {
|
552 | 552 | bf.destroySingletons();
|
553 | 553 | }
|
554 | 554 |
|
| 555 | + @Test |
| 556 | + public void testConstructorResourceInjectionWithNoCandidatesAndNoFallback() { |
| 557 | + DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); |
| 558 | + AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor(); |
| 559 | + bpp.setBeanFactory(bf); |
| 560 | + bf.addBeanPostProcessor(bpp); |
| 561 | + bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ConstructorWithoutFallbackBean.class)); |
| 562 | + |
| 563 | + try { |
| 564 | + bf.getBean("annotatedBean"); |
| 565 | + fail("Should have thrown UnsatisfiedDependencyException"); |
| 566 | + } |
| 567 | + catch (UnsatisfiedDependencyException ex) { |
| 568 | + // expected |
| 569 | + } |
| 570 | + } |
| 571 | + |
555 | 572 | @Test
|
556 | 573 | public void testConstructorResourceInjectionWithMultipleCandidatesAsCollection() {
|
557 | 574 | DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
@@ -2048,6 +2065,21 @@ public NestedTestBean[] getNestedTestBeans() {
|
2048 | 2065 | }
|
2049 | 2066 |
|
2050 | 2067 |
|
| 2068 | + public static class ConstructorWithoutFallbackBean { |
| 2069 | + |
| 2070 | + protected ITestBean testBean3; |
| 2071 | + |
| 2072 | + @Autowired(required = false) |
| 2073 | + public ConstructorWithoutFallbackBean(ITestBean testBean3) { |
| 2074 | + this.testBean3 = testBean3; |
| 2075 | + } |
| 2076 | + |
| 2077 | + public ITestBean getTestBean3() { |
| 2078 | + return this.testBean3; |
| 2079 | + } |
| 2080 | + } |
| 2081 | + |
| 2082 | + |
2051 | 2083 | public static class ConstructorsCollectionResourceInjectionBean {
|
2052 | 2084 |
|
2053 | 2085 | protected ITestBean testBean3;
|
@@ -2113,7 +2145,6 @@ public static class MapFieldInjectionBean {
|
2113 | 2145 | @Autowired
|
2114 | 2146 | private Map<String, TestBean> testBeanMap;
|
2115 | 2147 |
|
2116 |
| - |
2117 | 2148 | public Map<String, TestBean> getTestBeanMap() {
|
2118 | 2149 | return this.testBeanMap;
|
2119 | 2150 | }
|
|
0 commit comments