Custom resolution of preferred constructors for createBean(Class)
Avoids side effects of traditional AUTOWIRE_CONSTRUCTOR algorithm. Closes gh-30041
This commit is contained in:
@@ -2126,6 +2126,23 @@ class DefaultListableBeanFactoryTests {
|
||||
assertThat(tb.wasDestroyed()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void createBeanWithNonDefaultConstructor() {
|
||||
lbf.registerBeanDefinition("otherTestBean", new RootBeanDefinition(TestBean.class));
|
||||
TestBeanRecipient tb = lbf.createBean(TestBeanRecipient.class);
|
||||
assertThat(lbf.containsSingleton("otherTestBean")).isTrue();
|
||||
assertThat(tb.testBean).isEqualTo(lbf.getBean("otherTestBean"));
|
||||
lbf.destroyBean(tb);
|
||||
}
|
||||
|
||||
@Test
|
||||
void createBeanWithPreferredDefaultConstructor() {
|
||||
lbf.registerBeanDefinition("otherTestBean", new RootBeanDefinition(TestBean.class));
|
||||
TestBean tb = lbf.createBean(TestBean.class);
|
||||
assertThat(lbf.containsSingleton("otherTestBean")).isFalse();
|
||||
lbf.destroyBean(tb);
|
||||
}
|
||||
|
||||
@Test
|
||||
void configureBean() {
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
|
||||
Reference in New Issue
Block a user