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.BeanPostProcessor;
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.DependencyDescriptor;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
@ -1221,7 +1222,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
this.currentlyCreatedBean.set(beanName);
try {
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) {
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.config.BeanDefinition;
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.style.ToStringCreator;
import org.springframework.lang.Nullable;
@ -41,7 +41,7 @@ import org.springframework.util.StringUtils;
*/
public final class RegisteredBean {
private final ConfigurableBeanFactory beanFactory;
private final ConfigurableListableBeanFactory beanFactory;
private final Supplier<String> beanName;
@ -53,7 +53,7 @@ public final class RegisteredBean {
private final RegisteredBean parent;
private RegisteredBean(ConfigurableBeanFactory beanFactory, Supplier<String> beanName,
private RegisteredBean(ConfigurableListableBeanFactory beanFactory, Supplier<String> beanName,
boolean generatedBeanName, Supplier<RootBeanDefinition> mergedBeanDefinition,
@Nullable RegisteredBean parent) {
@ -71,7 +71,7 @@ public final class RegisteredBean {
* @param beanName the bean name
* @return a new {@link RegisteredBean} instance
*/
public static RegisteredBean of(ConfigurableBeanFactory beanFactory,
public static RegisteredBean of(ConfigurableListableBeanFactory beanFactory,
String beanName) {
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
*/
public ConfigurableBeanFactory getBeanFactory() {
public ConfigurableListableBeanFactory getBeanFactory() {
return this.beanFactory;
}
@ -172,7 +172,7 @@ public final class RegisteredBean {
/**
* Return the merged bean definition of the bean.
* @return the merged bean definition
* @see ConfigurableBeanFactory#getMergedBeanDefinition(String)
* @see ConfigurableListableBeanFactory#getMergedBeanDefinition(String)
*/
public RootBeanDefinition getMergedBeanDefinition() {
return this.mergedBeanDefinition.get();