diff --git a/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java b/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java index d37466141..8fe926ccc 100644 --- a/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java +++ b/src/main/java/org/springframework/data/mapping/model/AnnotationBasedPersistentProperty.java @@ -17,9 +17,9 @@ package org.springframework.data.mapping.model; import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; -import java.util.HashMap; import java.util.Map; import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -56,7 +56,7 @@ public abstract class AnnotationBasedPersistentProperty

, Optional> annotationCache = new HashMap<>(); + private final Map, Optional> annotationCache = new ConcurrentHashMap<>(); private final Lazy usePropertyAccess = Lazy.of(() -> { @@ -230,6 +230,12 @@ public abstract class AnnotationBasedPersistentProperty

Optional doFindAnnotation(Class annotationType) { + Optional annotation = annotationCache.get(annotationType); + + if (annotation != null) { + return (Optional) annotation; + } + return (Optional) annotationCache.computeIfAbsent(annotationType, type -> { return getAccessors() //