mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-05-04 05:17:15 +01:00
Fall back to type-based creation if no bean of the given name exists
Closes gh-30683
This commit is contained in:
+16
-7
@@ -143,7 +143,7 @@ public final class SpringBeanContainer implements BeanContainer {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (lifecycleOptions.useJpaCompliantCreation()) {
|
if (lifecycleOptions.useJpaCompliantCreation()) {
|
||||||
return new SpringContainedBean<>(
|
return new SpringContainedBean<>( // to be replaced with plain createBean(Class)
|
||||||
this.beanFactory.createBean(beanType, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false),
|
this.beanFactory.createBean(beanType, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false),
|
||||||
this.beanFactory::destroyBean);
|
this.beanFactory::destroyBean);
|
||||||
}
|
}
|
||||||
@@ -180,14 +180,23 @@ public final class SpringBeanContainer implements BeanContainer {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (lifecycleOptions.useJpaCompliantCreation()) {
|
if (lifecycleOptions.useJpaCompliantCreation()) {
|
||||||
Object bean = this.beanFactory.autowire(beanType, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false);
|
if (this.beanFactory.containsBean(name)) {
|
||||||
this.beanFactory.autowireBeanProperties(bean, AutowireCapableBeanFactory.AUTOWIRE_NO, false);
|
Object bean = this.beanFactory.autowire(beanType, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false);
|
||||||
this.beanFactory.applyBeanPropertyValues(bean, name);
|
this.beanFactory.autowireBeanProperties(bean, AutowireCapableBeanFactory.AUTOWIRE_NO, false);
|
||||||
bean = this.beanFactory.initializeBean(bean, name);
|
this.beanFactory.applyBeanPropertyValues(bean, name);
|
||||||
return new SpringContainedBean<>(bean, beanInstance -> this.beanFactory.destroyBean(name, beanInstance));
|
bean = this.beanFactory.initializeBean(bean, name);
|
||||||
|
return new SpringContainedBean<>(bean, beanInstance -> this.beanFactory.destroyBean(name, beanInstance));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return new SpringContainedBean<>( // to be replaced with plain createBean(Class)
|
||||||
|
this.beanFactory.createBean(beanType, AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR, false),
|
||||||
|
this.beanFactory::destroyBean);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return new SpringContainedBean<>(this.beanFactory.getBean(name, beanType));
|
return (this.beanFactory.containsBean(name) ?
|
||||||
|
new SpringContainedBean<>(this.beanFactory.getBean(name, beanType)) :
|
||||||
|
new SpringContainedBean<>(this.beanFactory.getBean(beanType)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (BeansException ex) {
|
catch (BeansException ex) {
|
||||||
|
|||||||
Reference in New Issue
Block a user