diff --git a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboDeployApplicationListener.java b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboDeployApplicationListener.java index 37c2343604a..203322c3cb8 100644 --- a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboDeployApplicationListener.java +++ b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/context/DubboDeployApplicationListener.java @@ -33,6 +33,7 @@ import org.apache.dubbo.rpc.model.ModelConstants; import org.apache.dubbo.rpc.model.ModuleModel; import org.springframework.beans.BeansException; +import org.springframework.beans.factory.support.DefaultSingletonBeanRegistry; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.context.ApplicationListener; @@ -109,8 +110,12 @@ public void onApplicationEvent(ApplicationContextEvent event) { private void onContextRefreshedEvent(ContextRefreshedEvent event) { ModuleDeployer deployer = moduleModel.getDeployer(); Assert.notNull(deployer, "Module deployer is null"); + Object singletonMutex = ((DefaultSingletonBeanRegistry) applicationContext.getAutowireCapableBeanFactory()).getSingletonMutex(); // start module - Future future = deployer.start(); + Future future = null; + synchronized (singletonMutex) { + future = deployer.start(); + } // if the module does not start in background, await finish if (!deployer.isBackground()) { @@ -140,7 +145,7 @@ private void onContextClosedEvent(ContextClosedEvent event) { @Override public int getOrder() { - return LOWEST_PRECEDENCE; + return HIGHEST_PRECEDENCE; } }