Separate factory method cache for introspection purposes
Issue: SPR-17358 Issue: SPR-8891
This commit is contained in:
@@ -775,6 +775,7 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
}
|
||||
}
|
||||
|
||||
mbd.factoryMethodToIntrospect = uniqueCandidate;
|
||||
if (commonType == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -337,9 +337,7 @@ class ConstructorResolver {
|
||||
}
|
||||
}
|
||||
}
|
||||
synchronized (mbd.constructorArgumentLock) {
|
||||
mbd.resolvedConstructorOrFactoryMethod = uniqueCandidate;
|
||||
}
|
||||
mbd.factoryMethodToIntrospect = uniqueCandidate;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -448,6 +446,7 @@ class ConstructorResolver {
|
||||
if (candidateList.size() == 1 && explicitArgs == null && !mbd.hasConstructorArgumentValues()) {
|
||||
Method uniqueCandidate = candidateList.get(0);
|
||||
if (uniqueCandidate.getParameterCount() == 0) {
|
||||
mbd.factoryMethodToIntrospect = uniqueCandidate;
|
||||
synchronized (mbd.constructorArgumentLock) {
|
||||
mbd.resolvedConstructorOrFactoryMethod = uniqueCandidate;
|
||||
mbd.constructorArgumentsResolved = true;
|
||||
@@ -598,6 +597,7 @@ class ConstructorResolver {
|
||||
}
|
||||
|
||||
if (explicitArgs == null && argsHolderToUse != null) {
|
||||
mbd.factoryMethodToIntrospect = factoryMethodToUse;
|
||||
argsHolderToUse.storeCache(mbd, factoryMethodToUse);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -755,14 +755,8 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
|
||||
String beanDefinitionName = BeanFactoryUtils.transformedBeanName(beanName);
|
||||
resolveBeanClass(mbd, beanDefinitionName);
|
||||
if (mbd.isFactoryMethodUnique) {
|
||||
boolean resolve;
|
||||
synchronized (mbd.constructorArgumentLock) {
|
||||
resolve = (mbd.resolvedConstructorOrFactoryMethod == null);
|
||||
}
|
||||
if (resolve) {
|
||||
new ConstructorResolver(this).resolveFactoryMethodIfPossible(mbd);
|
||||
}
|
||||
if (mbd.isFactoryMethodUnique && mbd.factoryMethodToIntrospect == null) {
|
||||
new ConstructorResolver(this).resolveFactoryMethodIfPossible(mbd);
|
||||
}
|
||||
return resolver.isAutowireCandidate(
|
||||
new BeanDefinitionHolder(mbd, beanName, getAliases(beanDefinitionName)), descriptor);
|
||||
|
||||
@@ -75,6 +75,10 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
|
||||
@Nullable
|
||||
volatile ResolvableType factoryMethodReturnType;
|
||||
|
||||
/** Package-visible field for caching a unique factory method candidate for introspection. */
|
||||
@Nullable
|
||||
volatile Method factoryMethodToIntrospect;
|
||||
|
||||
/** Common lock for the four constructor fields below. */
|
||||
final Object constructorArgumentLock = new Object();
|
||||
|
||||
@@ -370,10 +374,7 @@ public class RootBeanDefinition extends AbstractBeanDefinition {
|
||||
*/
|
||||
@Nullable
|
||||
public Method getResolvedFactoryMethod() {
|
||||
synchronized (this.constructorArgumentLock) {
|
||||
Executable candidate = this.resolvedConstructorOrFactoryMethod;
|
||||
return (candidate instanceof Method ? (Method) candidate : null);
|
||||
}
|
||||
return this.factoryMethodToIntrospect;
|
||||
}
|
||||
|
||||
public void registerExternallyManagedConfigMember(Member configMember) {
|
||||
|
||||
Reference in New Issue
Block a user