InjectionMetadata caching per bean name needs to refresh when bean class changes

Issue: SPR-11246
This commit is contained in:
Juergen Hoeller 2013-12-19 23:49:31 +01:00
parent 2faf008c2e
commit b1460742c3
4 changed files with 11 additions and 6 deletions

View File

@ -317,10 +317,10 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean
// 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) {
if (InjectionMetadata.needsRefresh(metadata, clazz)) {
synchronized (this.injectionMetadataCache) {
metadata = this.injectionMetadataCache.get(cacheKey);
if (metadata == null) {
if (InjectionMetadata.needsRefresh(metadata, clazz)) {
metadata = buildAutowiringMetadata(clazz);
this.injectionMetadataCache.put(cacheKey, metadata);
}

View File

@ -90,6 +90,11 @@ public class InjectionMetadata {
}
public static boolean needsRefresh(InjectionMetadata metadata, Class<?> clazz) {
return (metadata == null || !metadata.targetClass.equals(clazz));
}
public static abstract class InjectedElement {
protected final Member member;

View File

@ -315,10 +315,10 @@ public class CommonAnnotationBeanPostProcessor extends InitDestroyAnnotationBean
// 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) {
if (InjectionMetadata.needsRefresh(metadata, clazz)) {
synchronized (this.injectionMetadataCache) {
metadata = this.injectionMetadataCache.get(cacheKey);
if (metadata == null) {
if (InjectionMetadata.needsRefresh(metadata, clazz)) {
LinkedList<InjectionMetadata.InjectedElement> elements = new LinkedList<InjectionMetadata.InjectedElement>();
Class<?> targetClass = clazz;

View File

@ -380,10 +380,10 @@ public class PersistenceAnnotationBeanPostProcessor
// 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) {
if (InjectionMetadata.needsRefresh(metadata, clazz)) {
synchronized (this.injectionMetadataCache) {
metadata = this.injectionMetadataCache.get(cacheKey);
if (metadata == null) {
if (InjectionMetadata.needsRefresh(metadata, clazz)) {
LinkedList<InjectionMetadata.InjectedElement> elements = new LinkedList<InjectionMetadata.InjectedElement>();
Class<?> targetClass = clazz;