7474import org .springframework .core .ParameterNameDiscoverer ;
7575import org .springframework .core .PriorityOrdered ;
7676import org .springframework .util .ClassUtils ;
77+ import org .springframework .util .ConcurrentReferenceHashMap ;
7778import org .springframework .util .ObjectUtils ;
7879import org .springframework .util .ReflectionUtils ;
7980import org .springframework .util .StringUtils ;
@@ -151,6 +152,10 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
151152 private final Map <Class , PropertyDescriptor []> filteredPropertyDescriptorsCache =
152153 new ConcurrentHashMap <Class , PropertyDescriptor []>(64 );
153154
155+ /** Cache of unique declared methods **/
156+ private final ConcurrentReferenceHashMap <Class , Method []> uniqueDeclaredMethodsCache =
157+ new ConcurrentReferenceHashMap <Class , Method []>();
158+
154159
155160 /**
156161 * Create a new AbstractAutowireCapableBeanFactory.
@@ -648,7 +653,7 @@ protected Class<?> getTypeForFactoryMethod(String beanName, RootBeanDefinition m
648653 // If all factory methods have the same return type, return that type.
649654 // Can't clearly figure out exact method due to type converting / autowiring!
650655 int minNrOfArgs = mbd .getConstructorArgumentValues ().getArgumentCount ();
651- Method [] candidates = ReflectionUtils . getUniqueDeclaredMethods (factoryClass );
656+ Method [] candidates = getUniqueDeclaredMethods (factoryClass );
652657 Set <Class <?>> returnTypes = new HashSet <Class <?>>(1 );
653658 for (Method factoryMethod : candidates ) {
654659 if (Modifier .isStatic (factoryMethod .getModifiers ()) == isStatic &&
@@ -671,6 +676,15 @@ protected Class<?> getTypeForFactoryMethod(String beanName, RootBeanDefinition m
671676 }
672677 }
673678
679+ private Method [] getUniqueDeclaredMethods (Class factoryClass ) {
680+ Method [] methods = this .uniqueDeclaredMethodsCache .get (factoryClass );
681+ if (methods == null ) {
682+ methods = ReflectionUtils .getUniqueDeclaredMethods (factoryClass );
683+ this .uniqueDeclaredMethodsCache .put (factoryClass , methods );
684+ }
685+ return methods ;
686+ }
687+
674688 /**
675689 * This implementation attempts to query the FactoryBean's generic parameter metadata
676690 * if present to determine the object type. If not present, i.e. the FactoryBean is
0 commit comments