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 dc474498d6..3bbd3ce241 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 @@ -148,7 +148,7 @@ public class ReferenceBean private MutablePropertyValues propertyValues; // actual reference config - private ReferenceConfig referenceConfig; + private volatile ReferenceConfig referenceConfig; // ReferenceBeanManager private ReferenceBeanManager referenceBeanManager; @@ -423,15 +423,22 @@ public class ReferenceBean private Object getCallProxy() throws Exception { if (referenceConfig == null) { - referenceBeanManager.initReferenceBean(this); - applicationContext - .getBean(DubboConfigApplicationListener.class.getName(), DubboConfigApplicationListener.class) - .init(); - logger.warn( - CONFIG_DUBBO_BEAN_INITIALIZER, - "", - "", - "ReferenceBean is not ready yet, please make sure to call reference interface method after dubbo is started."); + synchronized (LockUtils.getSingletonMutex(applicationContext)) { + if (referenceConfig == null) { + referenceBeanManager.initReferenceBean(this); + applicationContext + .getBean( + DubboConfigApplicationListener.class.getName(), + DubboConfigApplicationListener.class) + .init(); + logger.warn( + CONFIG_DUBBO_BEAN_INITIALIZER, + "", + "", + "ReferenceBean is not ready yet, please make sure to " + + "call reference interface method after dubbo is started."); + } + } } // get reference proxy // Subclasses should synchronize on the given Object if they perform any sort of extended singleton creation diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboConfigApplicationListener.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboConfigApplicationListener.java index fa9d5b2b0b..499e81d679 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboConfigApplicationListener.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboConfigApplicationListener.java @@ -60,7 +60,7 @@ public class DubboConfigApplicationListener } } - public void init() { + public synchronized void init() { // It's expected to be notified at // org.springframework.context.support.AbstractApplicationContext.registerListeners(), // before loading non-lazy singleton beans. At this moment, all BeanFactoryPostProcessor have been processed,