Cache InjectionMetadata per bean name instead of per Class, if possible

Issue: SPR-11027
This commit is contained in:
Juergen Hoeller
2013-10-26 14:03:11 +02:00
parent 14b9931ee3
commit 4675bc4e0c
3 changed files with 17 additions and 9 deletions

View File

@@ -312,10 +312,12 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
private InjectionMetadata findResourceMetadata(String beanName, final Class<?> clazz) {
// Quick check on the concurrent map first, with minimal locking.
InjectionMetadata metadata = this.injectionMetadataCache.get(beanName);
// Fall back to class name as cache key, for backwards compatibility with custom callers.
String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
if (metadata == null) {
synchronized (this.injectionMetadataCache) {
metadata = this.injectionMetadataCache.get(beanName);
metadata = this.injectionMetadataCache.get(cacheKey);
if (metadata == null) {
LinkedList<InjectionMetadata.InjectedElement> elements = new LinkedList<InjectionMetadata.InjectedElement>();
Class<?> targetClass = clazz;
@@ -389,7 +391,7 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
while (targetClass != null && targetClass != Object.class);
metadata = new InjectionMetadata(clazz, elements);
this.injectionMetadataCache.put(beanName, metadata);
this.injectionMetadataCache.put(cacheKey, metadata);
}
}
}