Skip to content

Commit 8ecae86

Browse files
committed
Cache attribute methods in AnnotationUtils
Issue: SPR-11512
1 parent d5974a1 commit 8ecae86

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ public abstract class AnnotationUtils {
121121
private static final Map<Class<? extends Annotation>, Map<String, String>> attributeAliasesCache =
122122
new ConcurrentReferenceHashMap<Class<? extends Annotation>, Map<String, String>>(256);
123123

124+
private static final Map<Class<? extends Annotation>, List<Method>> attributeMethodsCache =
125+
new ConcurrentReferenceHashMap<Class<? extends Annotation>, List<Method>>(256);
126+
124127
private static transient Log logger;
125128

126129

@@ -1311,13 +1314,22 @@ static String getAliasedAttributeName(Method attribute, Class<? extends Annotati
13111314
* @since 4.2
13121315
*/
13131316
static List<Method> getAttributeMethods(Class<? extends Annotation> annotationType) {
1314-
List<Method> methods = new ArrayList<Method>();
1317+
1318+
List<Method> methods = attributeMethodsCache.get(annotationType);
1319+
if (methods != null) {
1320+
return methods;
1321+
}
1322+
1323+
methods = new ArrayList<Method>();
13151324
for (Method method : annotationType.getDeclaredMethods()) {
13161325
if ((method.getParameterTypes().length == 0) && (method.getReturnType() != void.class)) {
13171326
ReflectionUtils.makeAccessible(method);
13181327
methods.add(method);
13191328
}
13201329
}
1330+
1331+
attributeMethodsCache.put(annotationType, methods);
1332+
13211333
return methods;
13221334
}
13231335

0 commit comments

Comments
 (0)