diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java index e3d3028a444..bf73508dd5d 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ServiceConfig.java @@ -512,7 +512,8 @@ private void doExportUrls(RegisterTypeEnum registerType) { providerModel.setDestroyRunner(getDestroyRunner()); repository.registerProvider(providerModel); - List registryURLs = ConfigValidationUtils.loadRegistries(this, true); + List registryURLs = !Boolean.FALSE.equals(isRegister()) ? + ConfigValidationUtils.loadRegistries(this, true) : Collections.emptyList(); MetricsEventBus.post(RegistryEvent.toRsEvent(module.getApplicationModel(), getUniqueServiceName(), protocols.size() * registryURLs.size()), () -> { @@ -546,6 +547,9 @@ private void doExportUrlsFor1Protocol(ProtocolConfig protocolConfig, List r processServiceExecutor(url); + if (CollectionUtils.isEmpty(registryURLs)) { + registerType = RegisterTypeEnum.NEVER_REGISTER; + } exportUrl(url, registryURLs, registerType); } diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java index 4e9c20d415d..7b28528bfbd 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/utils/ConfigValidationUtils.java @@ -124,6 +124,7 @@ import static org.apache.dubbo.config.Constants.NAME; import static org.apache.dubbo.config.Constants.ORGANIZATION; import static org.apache.dubbo.config.Constants.OWNER; +import static org.apache.dubbo.config.Constants.REGISTER_KEY; import static org.apache.dubbo.config.Constants.STATUS_KEY; import static org.apache.dubbo.monitor.Constants.LOGSTAT_PROTOCOL; import static org.apache.dubbo.registry.Constants.REGISTER_IP_KEY; @@ -225,7 +226,10 @@ public static List loadRegistries(AbstractInterfaceConfig interfaceConfig, .setScopeModel(interfaceConfig.getScopeModel()) .build(); // provider delay register state will be checked in RegistryProtocol#export - if (provider || url.getParameter(SUBSCRIBE_KEY, true)) { + if (provider && url.getParameter(REGISTER_KEY, true)) { + registryList.add(url); + } + if (!provider && url.getParameter(SUBSCRIBE_KEY, true)) { registryList.add(url); } }