Browse Source

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
pull/28944/head
Stephane Nicoll 3 years ago
parent
commit
3c76437868
  1. 3
      spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java
  2. 12
      spring-beans/src/main/java/org/springframework/beans/factory/support/RegisteredBean.java

3
spring-beans/src/main/java/org/springframework/beans/factory/support/AbstractAutowireCapableBeanFactory.java

@ -61,6 +61,7 @@ import org.springframework.beans.factory.config.AutowiredPropertyMarker; @@ -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 @@ -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();

12
spring-beans/src/main/java/org/springframework/beans/factory/support/RegisteredBean.java

@ -22,7 +22,7 @@ import java.util.function.Supplier; @@ -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; @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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();

Loading…
Cancel
Save