Cache AbstractBeanFactory.isFactoryBean results
Add an additional cache to the `RootBeanDefinition` to save recalculating the result of `isFactoryBean`. Closes gh-23337
This commit is contained in:
committed by
Juergen Hoeller
parent
95edcb81b5
commit
527876d9a0
@@ -1333,6 +1333,7 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
|
||||
ObjectUtils.nullSafeEquals(mbd.getFactoryMethodName(), previous.getFactoryMethodName()) &&
|
||||
(mbd.targetType == null || mbd.targetType.equals(previous.targetType))) {
|
||||
mbd.targetType = previous.targetType;
|
||||
mbd.isFactoryBean = previous.isFactoryBean;
|
||||
mbd.resolvedTargetType = previous.resolvedTargetType;
|
||||
mbd.factoryMethodReturnType = previous.factoryMethodReturnType;
|
||||
mbd.factoryMethodToIntrospect = previous.factoryMethodToIntrospect;
|
||||
@@ -1541,8 +1542,13 @@ public abstract class AbstractBeanFactory extends FactoryBeanRegistrySupport imp
|
||||
* @param mbd the corresponding bean definition
|
||||
*/
|
||||
protected boolean isFactoryBean(String beanName, RootBeanDefinition mbd) {
|
||||
Class<?> beanType = predictBeanType(beanName, mbd, FactoryBean.class);
|
||||
return (beanType != null && FactoryBean.class.isAssignableFrom(beanType));
|
||||
Boolean result = mbd.isFactoryBean;
|
||||
if (result == null) {
|
||||
Class<?> beanType = predictBeanType(beanName, mbd, FactoryBean.class);
|
||||
result = beanType != null && FactoryBean.class.isAssignableFrom(beanType);
|
||||
mbd.isFactoryBean = result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -74,6 +74,10 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
|
||||
@Nullable
|
||||
volatile Class<?> resolvedTargetType;
|
||||
|
||||
/** Package-visible field for caching if the bean is a factory bean. */
|
||||
@Nullable
|
||||
volatile Boolean isFactoryBean;
|
||||
|
||||
/** Package-visible field for caching the return type of a generically typed factory method. */
|
||||
@Nullable
|
||||
volatile ResolvableType factoryMethodReturnType;
|
||||
|
||||
Reference in New Issue
Block a user