diff --git a/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java b/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java index 9518e4eb41..a245d51737 100644 --- a/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java +++ b/org.springframework.beans/src/main/java/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.java @@ -468,14 +468,14 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean value = resolvedCachedArgument(beanName, this.cachedFieldValue); } else { - synchronized (pvs) { + DependencyDescriptor descriptor = new DependencyDescriptor(field, this.required); + Set autowiredBeanNames = new LinkedHashSet(1); + TypeConverter typeConverter = beanFactory.getTypeConverter(); + value = beanFactory.resolveDependency(descriptor, beanName, autowiredBeanNames, typeConverter); + synchronized (this) { if (!this.cached) { - Set autowiredBeanNames = new LinkedHashSet(1); - TypeConverter typeConverter = beanFactory.getTypeConverter(); - DependencyDescriptor descriptor = new DependencyDescriptor(field, this.required); - this.cachedFieldValue = descriptor; - value = beanFactory.resolveDependency(descriptor, beanName, autowiredBeanNames, typeConverter); if (value != null) { + this.cachedFieldValue = descriptor; registerDependentBeans(beanName, autowiredBeanNames); if (autowiredBeanNames.size() == 1) { String autowiredBeanName = autowiredBeanNames.iterator().next(); @@ -491,10 +491,6 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean } this.cached = true; } - else { - // Already cached in the meantime... - value = resolvedCachedArgument(beanName, this.cachedFieldValue); - } } } if (value != null) { @@ -538,26 +534,29 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean arguments = resolveCachedArguments(beanName); } else { - synchronized (pvs) { + Class[] paramTypes = method.getParameterTypes(); + arguments = new Object[paramTypes.length]; + DependencyDescriptor[] descriptors = new DependencyDescriptor[paramTypes.length]; + Set autowiredBeanNames = new LinkedHashSet(paramTypes.length); + TypeConverter typeConverter = beanFactory.getTypeConverter(); + for (int i = 0; i < arguments.length; i++) { + MethodParameter methodParam = new MethodParameter(method, i); + GenericTypeResolver.resolveParameterType(methodParam, bean.getClass()); + descriptors[i] = new DependencyDescriptor(methodParam, this.required); + arguments[i] = beanFactory.resolveDependency( + descriptors[i], beanName, autowiredBeanNames, typeConverter); + if (arguments[i] == null) { + arguments = null; + break; + } + } + synchronized (this) { if (!this.cached) { - Class[] paramTypes = method.getParameterTypes(); - arguments = new Object[paramTypes.length]; - Set autowiredBeanNames = new LinkedHashSet(arguments.length); - TypeConverter typeConverter = beanFactory.getTypeConverter(); - this.cachedMethodArguments = new Object[arguments.length]; - for (int i = 0; i < arguments.length; i++) { - MethodParameter methodParam = new MethodParameter(method, i); - GenericTypeResolver.resolveParameterType(methodParam, bean.getClass()); - DependencyDescriptor descriptor = new DependencyDescriptor(methodParam, this.required); - this.cachedMethodArguments[i] = descriptor; - arguments[i] = beanFactory.resolveDependency( - descriptor, beanName, autowiredBeanNames, typeConverter); - if (arguments[i] == null) { - arguments = null; - break; - } - } if (arguments != null) { + this.cachedMethodArguments = new Object[arguments.length]; + for (int i = 0; i < arguments.length; i++) { + this.cachedMethodArguments[i] = descriptors[i]; + } registerDependentBeans(beanName, autowiredBeanNames); if (autowiredBeanNames.size() == paramTypes.length) { Iterator it = autowiredBeanNames.iterator(); @@ -579,10 +578,6 @@ public class AutowiredAnnotationBeanPostProcessor extends InstantiationAwareBean } this.cached = true; } - else { - // Already cached in the meantime... - arguments = resolveCachedArguments(beanName); - } } } if (arguments != null) {