74
74
import org .springframework .core .ParameterNameDiscoverer ;
75
75
import org .springframework .core .PriorityOrdered ;
76
76
import org .springframework .util .ClassUtils ;
77
+ import org .springframework .util .ConcurrentReferenceHashMap ;
77
78
import org .springframework .util .ObjectUtils ;
78
79
import org .springframework .util .ReflectionUtils ;
79
80
import org .springframework .util .StringUtils ;
@@ -151,6 +152,10 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
151
152
private final Map <Class , PropertyDescriptor []> filteredPropertyDescriptorsCache =
152
153
new ConcurrentHashMap <Class , PropertyDescriptor []>(64 );
153
154
155
+ /** Cache of unique declared methods **/
156
+ private final ConcurrentReferenceHashMap <Class , Method []> uniqueDeclaredMethodsCache =
157
+ new ConcurrentReferenceHashMap <Class , Method []>();
158
+
154
159
155
160
/**
156
161
* Create a new AbstractAutowireCapableBeanFactory.
@@ -648,7 +653,7 @@ protected Class<?> getTypeForFactoryMethod(String beanName, RootBeanDefinition m
648
653
// If all factory methods have the same return type, return that type.
649
654
// Can't clearly figure out exact method due to type converting / autowiring!
650
655
int minNrOfArgs = mbd .getConstructorArgumentValues ().getArgumentCount ();
651
- Method [] candidates = ReflectionUtils . getUniqueDeclaredMethods (factoryClass );
656
+ Method [] candidates = getUniqueDeclaredMethods (factoryClass );
652
657
Set <Class <?>> returnTypes = new HashSet <Class <?>>(1 );
653
658
for (Method factoryMethod : candidates ) {
654
659
if (Modifier .isStatic (factoryMethod .getModifiers ()) == isStatic &&
@@ -671,6 +676,15 @@ protected Class<?> getTypeForFactoryMethod(String beanName, RootBeanDefinition m
671
676
}
672
677
}
673
678
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
+
674
688
/**
675
689
* This implementation attempts to query the FactoryBean's generic parameter metadata
676
690
* if present to determine the object type. If not present, i.e. the FactoryBean is
0 commit comments