diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ReferenceBean.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ReferenceBean.java index afaa9fcd59f6..c22a280f0b76 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ReferenceBean.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ReferenceBean.java @@ -39,6 +39,7 @@ import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.beans.factory.support.DefaultSingletonBeanRegistry; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; @@ -343,7 +344,12 @@ private Object getCallProxy() throws Exception { throw new IllegalStateException("ReferenceBean is not ready yet, please make sure to call reference interface method after dubbo is started."); } //get reference proxy - return referenceConfig.get(); + //Subclasses should synchronize on the given Object if they perform any sort of extended singleton creation phase. + // In particular, subclasses should not have their own mutexes involved in singleton creation, to avoid the potential for deadlocks in lazy-init situations. + //The redundant type cast is to be compatible with earlier than spring-4.2 + synchronized (((DefaultSingletonBeanRegistry)getBeanFactory()).getSingletonMutex()) { + return referenceConfig.get(); + } } private class DubboReferenceLazyInitTargetSource extends AbstractLazyCreationTargetSource {