Update RegisteredBean to take a ConfigurableListableBeanFactory

This allows to have access to `getBeanDefinition` if the original
bean definition needs to be retrieved.

See gh-28936
This commit is contained in:
Stephane Nicoll 2022-08-08 14:00:49 +02:00
parent 832889d801
commit 3c76437868
2 changed files with 8 additions and 7 deletions

View File

@ -61,6 +61,7 @@ import org.springframework.beans.factory.config.AutowiredPropertyMarker;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanPostProcessor; import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.ConstructorArgumentValues; import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.factory.config.DependencyDescriptor; import org.springframework.beans.factory.config.DependencyDescriptor;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor; import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
@ -1221,7 +1222,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
this.currentlyCreatedBean.set(beanName); this.currentlyCreatedBean.set(beanName);
try { try {
if (supplier instanceof InstanceSupplier<?> instanceSupplier) { if (supplier instanceof InstanceSupplier<?> instanceSupplier) {
return instanceSupplier.get(RegisteredBean.of(this, beanName)); return instanceSupplier.get(RegisteredBean.of((ConfigurableListableBeanFactory) this, beanName));
} }
if (supplier instanceof ThrowingSupplier<?> throwableSupplier) { if (supplier instanceof ThrowingSupplier<?> throwableSupplier) {
return throwableSupplier.getWithException(); return throwableSupplier.getWithException();

View File

@ -22,7 +22,7 @@ import java.util.function.Supplier;
import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder; import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.core.ResolvableType; import org.springframework.core.ResolvableType;
import org.springframework.core.style.ToStringCreator; import org.springframework.core.style.ToStringCreator;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
@ -41,7 +41,7 @@ import org.springframework.util.StringUtils;
*/ */
public final class RegisteredBean { public final class RegisteredBean {
private final ConfigurableBeanFactory beanFactory; private final ConfigurableListableBeanFactory beanFactory;
private final Supplier<String> beanName; private final Supplier<String> beanName;
@ -53,7 +53,7 @@ public final class RegisteredBean {
private final RegisteredBean parent; private final RegisteredBean parent;
private RegisteredBean(ConfigurableBeanFactory beanFactory, Supplier<String> beanName, private RegisteredBean(ConfigurableListableBeanFactory beanFactory, Supplier<String> beanName,
boolean generatedBeanName, Supplier<RootBeanDefinition> mergedBeanDefinition, boolean generatedBeanName, Supplier<RootBeanDefinition> mergedBeanDefinition,
@Nullable RegisteredBean parent) { @Nullable RegisteredBean parent) {
@ -71,7 +71,7 @@ public final class RegisteredBean {
* @param beanName the bean name * @param beanName the bean name
* @return a new {@link RegisteredBean} instance * @return a new {@link RegisteredBean} instance
*/ */
public static RegisteredBean of(ConfigurableBeanFactory beanFactory, public static RegisteredBean of(ConfigurableListableBeanFactory beanFactory,
String beanName) { String beanName) {
Assert.notNull(beanFactory, "'beanFactory' must not be null"); Assert.notNull(beanFactory, "'beanFactory' must not be null");
@ -149,7 +149,7 @@ public final class RegisteredBean {
* Return the bean factory containing the bean. * Return the bean factory containing the bean.
* @return the bean factory * @return the bean factory
*/ */
public ConfigurableBeanFactory getBeanFactory() { public ConfigurableListableBeanFactory getBeanFactory() {
return this.beanFactory; return this.beanFactory;
} }
@ -172,7 +172,7 @@ public final class RegisteredBean {
/** /**
* Return the merged bean definition of the bean. * Return the merged bean definition of the bean.
* @return the merged bean definition * @return the merged bean definition
* @see ConfigurableBeanFactory#getMergedBeanDefinition(String) * @see ConfigurableListableBeanFactory#getMergedBeanDefinition(String)
*/ */
public RootBeanDefinition getMergedBeanDefinition() { public RootBeanDefinition getMergedBeanDefinition() {
return this.mergedBeanDefinition.get(); return this.mergedBeanDefinition.get();