|
|
|
|
@ -1271,10 +1271,11 @@ class DefaultListableBeanFactoryTests {
@@ -1271,10 +1271,11 @@ class DefaultListableBeanFactoryTests {
|
|
|
|
|
lbf.registerBeanDefinition("rod", bd); |
|
|
|
|
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class); |
|
|
|
|
lbf.registerBeanDefinition("rod2", bd2); |
|
|
|
|
assertThatExceptionOfType(UnsatisfiedDependencyException.class).isThrownBy(() -> |
|
|
|
|
lbf.autowire(ConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false)) |
|
|
|
|
.withMessageContaining("rod") |
|
|
|
|
.withMessageContaining("rod2"); |
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(UnsatisfiedDependencyException.class) |
|
|
|
|
.isThrownBy(() -> lbf.autowire(ConstructorDependency.class, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false)) |
|
|
|
|
.withMessageContaining("rod") |
|
|
|
|
.withMessageContaining("rod2"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -1336,11 +1337,12 @@ class DefaultListableBeanFactoryTests {
@@ -1336,11 +1337,12 @@ class DefaultListableBeanFactoryTests {
|
|
|
|
|
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class); |
|
|
|
|
bd2.setDependsOn("tb1"); |
|
|
|
|
lbf.registerBeanDefinition("tb2", bd2); |
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> |
|
|
|
|
lbf.preInstantiateSingletons()) |
|
|
|
|
.withMessageContaining("Circular") |
|
|
|
|
.withMessageContaining("'tb2'") |
|
|
|
|
.withMessageContaining("'tb1'"); |
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class) |
|
|
|
|
.isThrownBy(() -> lbf.preInstantiateSingletons()) |
|
|
|
|
.withMessageContaining("Circular") |
|
|
|
|
.withMessageContaining("'tb2'") |
|
|
|
|
.withMessageContaining("'tb1'"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -1354,11 +1356,12 @@ class DefaultListableBeanFactoryTests {
@@ -1354,11 +1356,12 @@ class DefaultListableBeanFactoryTests {
|
|
|
|
|
RootBeanDefinition bd3 = new RootBeanDefinition(TestBean.class); |
|
|
|
|
bd3.setDependsOn("tb1"); |
|
|
|
|
lbf.registerBeanDefinition("tb3", bd3); |
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class).isThrownBy( |
|
|
|
|
lbf::preInstantiateSingletons) |
|
|
|
|
.withMessageContaining("Circular") |
|
|
|
|
.withMessageContaining("'tb3'") |
|
|
|
|
.withMessageContaining("'tb1'"); |
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class) |
|
|
|
|
.isThrownBy(lbf::preInstantiateSingletons) |
|
|
|
|
.withMessageContaining("Circular") |
|
|
|
|
.withMessageContaining("'tb3'") |
|
|
|
|
.withMessageContaining("'tb1'"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -1493,10 +1496,11 @@ class DefaultListableBeanFactoryTests {
@@ -1493,10 +1496,11 @@ class DefaultListableBeanFactoryTests {
|
|
|
|
|
RootBeanDefinition bd2 = new RootBeanDefinition(HighPriorityTestBean.class); |
|
|
|
|
lbf.registerBeanDefinition("bd1", bd1); |
|
|
|
|
lbf.registerBeanDefinition("bd2", bd2); |
|
|
|
|
assertThatExceptionOfType(NoUniqueBeanDefinitionException.class).isThrownBy(() -> |
|
|
|
|
lbf.getBean(TestBean.class)) |
|
|
|
|
.withMessageContaining("Multiple beans found with the same priority") |
|
|
|
|
.withMessageContaining("5"); // conflicting priority
|
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(NoUniqueBeanDefinitionException.class) |
|
|
|
|
.isThrownBy(() -> lbf.getBean(TestBean.class)) |
|
|
|
|
.withMessageContaining("Multiple beans found with the same priority") |
|
|
|
|
.withMessageContaining("5"); // conflicting priority
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -1698,9 +1702,9 @@ class DefaultListableBeanFactoryTests {
@@ -1698,9 +1702,9 @@ class DefaultListableBeanFactoryTests {
|
|
|
|
|
lbf.registerBeanDefinition("bd1", bd1); |
|
|
|
|
lbf.registerBeanDefinition("bd2", bd2); |
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(NoUniqueBeanDefinitionException.class).isThrownBy(() -> |
|
|
|
|
lbf.getBean(ConstructorDependency.class, 42)) |
|
|
|
|
.withMessageContaining("more than one 'primary'"); |
|
|
|
|
assertThatExceptionOfType(NoUniqueBeanDefinitionException.class) |
|
|
|
|
.isThrownBy(() -> lbf.getBean(ConstructorDependency.class, 42)) |
|
|
|
|
.withMessageContaining("more than one 'primary'"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -1881,10 +1885,11 @@ class DefaultListableBeanFactoryTests {
@@ -1881,10 +1885,11 @@ class DefaultListableBeanFactoryTests {
|
|
|
|
|
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class); |
|
|
|
|
lbf.registerBeanDefinition("test", bd); |
|
|
|
|
lbf.registerBeanDefinition("spouse", bd2); |
|
|
|
|
assertThatExceptionOfType(UnsatisfiedDependencyException.class).isThrownBy(() -> |
|
|
|
|
lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true)) |
|
|
|
|
.withMessageContaining("test") |
|
|
|
|
.withMessageContaining("spouse"); |
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(UnsatisfiedDependencyException.class) |
|
|
|
|
.isThrownBy(() -> lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true)) |
|
|
|
|
.withMessageContaining("test") |
|
|
|
|
.withMessageContaining("spouse"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -1946,10 +1951,11 @@ class DefaultListableBeanFactoryTests {
@@ -1946,10 +1951,11 @@ class DefaultListableBeanFactoryTests {
|
|
|
|
|
RootBeanDefinition bd2 = new RootBeanDefinition(HighPriorityTestBean.class); |
|
|
|
|
lbf.registerBeanDefinition("test", bd); |
|
|
|
|
lbf.registerBeanDefinition("spouse", bd2); |
|
|
|
|
assertThatExceptionOfType(UnsatisfiedDependencyException.class).isThrownBy(() -> |
|
|
|
|
lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true)) |
|
|
|
|
.withCauseExactlyInstanceOf(NoUniqueBeanDefinitionException.class) |
|
|
|
|
.withMessageContaining("5"); |
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(UnsatisfiedDependencyException.class) |
|
|
|
|
.isThrownBy(() -> lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true)) |
|
|
|
|
.withCauseExactlyInstanceOf(NoUniqueBeanDefinitionException.class) |
|
|
|
|
.withMessageContaining("5"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
@ -2185,19 +2191,21 @@ class DefaultListableBeanFactoryTests {
@@ -2185,19 +2191,21 @@ class DefaultListableBeanFactoryTests {
|
|
|
|
|
@Test |
|
|
|
|
void beanDefinitionWithInterface() { |
|
|
|
|
lbf.registerBeanDefinition("test", new RootBeanDefinition(ITestBean.class)); |
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> |
|
|
|
|
lbf.getBean("test")) |
|
|
|
|
.withMessageContaining("interface") |
|
|
|
|
.satisfies(ex -> assertThat(ex.getBeanName()).isEqualTo("test")); |
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class) |
|
|
|
|
.isThrownBy(() -> lbf.getBean("test")) |
|
|
|
|
.withMessageContaining("interface") |
|
|
|
|
.satisfies(ex -> assertThat(ex.getBeanName()).isEqualTo("test")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
void beanDefinitionWithAbstractClass() { |
|
|
|
|
lbf.registerBeanDefinition("test", new RootBeanDefinition(AbstractBeanFactory.class)); |
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() -> |
|
|
|
|
lbf.getBean("test")) |
|
|
|
|
.withMessageContaining("abstract") |
|
|
|
|
.satisfies(ex -> assertThat(ex.getBeanName()).isEqualTo("test")); |
|
|
|
|
|
|
|
|
|
assertThatExceptionOfType(BeanCreationException.class) |
|
|
|
|
.isThrownBy(() -> lbf.getBean("test")) |
|
|
|
|
.withMessageContaining("abstract") |
|
|
|
|
.satisfies(ex -> assertThat(ex.getBeanName()).isEqualTo("test")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|