Consistent throwing of last UnsatisfiedDependencyException if available and no constructor resolved
Issue: SPR-12543
This commit is contained in:
@@ -2023,6 +2023,30 @@ public class DefaultListableBeanFactoryTests {
|
||||
lbf.preInstantiateSingletons();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorDependencyWithClassResolution() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(ConstructorDependencyWithClassResolution.class);
|
||||
bd.getConstructorArgumentValues().addGenericArgumentValue("java.lang.String");
|
||||
lbf.registerBeanDefinition("test", bd);
|
||||
lbf.preInstantiateSingletons();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorDependencyWithUnresolvableClass() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition bd = new RootBeanDefinition(ConstructorDependencyWithClassResolution.class);
|
||||
bd.getConstructorArgumentValues().addGenericArgumentValue("java.lang.Strin");
|
||||
lbf.registerBeanDefinition("test", bd);
|
||||
try {
|
||||
lbf.preInstantiateSingletons();
|
||||
fail("Should have thrown UnsatisfiedDependencyException");
|
||||
}
|
||||
catch (UnsatisfiedDependencyException expected) {
|
||||
assertTrue(expected.toString().contains("java.lang.Strin"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBeanDefinitionWithInterface() {
|
||||
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
|
||||
@@ -2033,7 +2057,7 @@ public class DefaultListableBeanFactoryTests {
|
||||
}
|
||||
catch (BeanCreationException ex) {
|
||||
assertEquals("test", ex.getBeanName());
|
||||
assertTrue(ex.getMessage().toLowerCase().indexOf("interface") != -1);
|
||||
assertTrue(ex.getMessage().toLowerCase().contains("interface"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2047,7 +2071,7 @@ public class DefaultListableBeanFactoryTests {
|
||||
}
|
||||
catch (BeanCreationException ex) {
|
||||
assertEquals("test", ex.getBeanName());
|
||||
assertTrue(ex.getMessage().toLowerCase().indexOf("abstract") != -1);
|
||||
assertTrue(ex.getMessage().toLowerCase().contains("abstract"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2739,6 +2763,16 @@ public class DefaultListableBeanFactoryTests {
|
||||
}
|
||||
|
||||
|
||||
public static class ConstructorDependencyWithClassResolution {
|
||||
|
||||
public ConstructorDependencyWithClassResolution(Class<?> clazz) {
|
||||
}
|
||||
|
||||
public ConstructorDependencyWithClassResolution() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class BeanWithDisposableBean implements DisposableBean {
|
||||
|
||||
private static boolean closed;
|
||||
|
||||
Reference in New Issue
Block a user