diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java index 0761822b86c..5bed8e8e3c7 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/AbstractInterfaceConfig.java @@ -312,6 +312,10 @@ private void convertRegistryIdsToRegistries() { } + protected boolean notHasSelfRegistryProperty() { + return CollectionUtils.isEmpty(registries) && StringUtils.isEmpty(registryIds); + } + public void completeCompoundConfigs(AbstractInterfaceConfig interfaceConfig) { if (interfaceConfig != null) { if (application == null) { @@ -320,15 +324,16 @@ public void completeCompoundConfigs(AbstractInterfaceConfig interfaceConfig) { if (module == null) { setModule(interfaceConfig.getModule()); } - if (registries == null) { + if (notHasSelfRegistryProperty()) { setRegistries(interfaceConfig.getRegistries()); + setRegistryIds(interfaceConfig.getRegistryIds()); } if (monitor == null) { setMonitor(interfaceConfig.getMonitor()); } } if (module != null) { - if (registries == null) { + if (notHasSelfRegistryProperty()) { setRegistries(module.getRegistries()); } if (monitor == null) { @@ -336,8 +341,9 @@ public void completeCompoundConfigs(AbstractInterfaceConfig interfaceConfig) { } } if (application != null) { - if (registries == null) { + if (notHasSelfRegistryProperty()) { setRegistries(application.getRegistries()); + setRegistryIds(application.getRegistryIds()); } if (monitor == null) { setMonitor(application.getMonitor()); @@ -346,10 +352,9 @@ public void completeCompoundConfigs(AbstractInterfaceConfig interfaceConfig) { } protected void computeValidRegistryIds() { - if (StringUtils.isEmpty(getRegistryIds())) { - if (getApplication() != null && StringUtils.isNotEmpty(getApplication().getRegistryIds())) { - setRegistryIds(getApplication().getRegistryIds()); - } + if (application != null && notHasSelfRegistryProperty()) { + setRegistries(application.getRegistries()); + setRegistryIds(application.getRegistryIds()); } } diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java index 966b384c988..2de2959dcfb 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java @@ -259,12 +259,14 @@ public void resolveFile() { @Override protected void computeValidRegistryIds() { - super.computeValidRegistryIds(); - if (StringUtils.isEmpty(getRegistryIds())) { - if (getConsumer() != null && StringUtils.isNotEmpty(getConsumer().getRegistryIds())) { - setRegistryIds(getConsumer().getRegistryIds()); + if (consumer != null) { + if (notHasSelfRegistryProperty()) { + setRegistries(consumer.getRegistries()); + setRegistryIds(consumer.getRegistryIds()); } } + + super.computeValidRegistryIds(); } @Parameter(excluded = true) diff --git a/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java b/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java index f1b14d6df62..11c3bfc54f5 100644 --- a/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java +++ b/dubbo-common/src/main/java/org/apache/dubbo/config/ServiceConfigBase.java @@ -202,32 +202,35 @@ public void checkDefault() throws IllegalStateException { } public void checkProtocol() { + if (provider != null && notHasSelfProtocolProperty()) { + setProtocols(provider.getProtocols()); + setProtocolIds(provider.getProtocolIds()); + } + if (CollectionUtils.isEmpty(protocols) && provider != null) { setProtocols(provider.getProtocols()); } convertProtocolIdsToProtocols(); } + private boolean notHasSelfProtocolProperty() { + return CollectionUtils.isEmpty(protocols) && StringUtils.isEmpty(protocolIds); + } + public void completeCompoundConfigs() { super.completeCompoundConfigs(provider); if (provider != null) { - if (protocols == null) { + if (notHasSelfProtocolProperty()) { setProtocols(provider.getProtocols()); + setProtocolIds(provider.getProtocolIds()); } if (configCenter == null) { setConfigCenter(provider.getConfigCenter()); } - if (StringUtils.isEmpty(registryIds)) { - setRegistryIds(provider.getRegistryIds()); - } - if (StringUtils.isEmpty(protocolIds)) { - setProtocolIds(provider.getProtocolIds()); - } } } private void convertProtocolIdsToProtocols() { - computeValidProtocolIds(); if (StringUtils.isEmpty(protocolIds)) { if (CollectionUtils.isEmpty(protocols)) { List protocolConfigs = ApplicationModel.getConfigManager().getDefaultProtocols(); @@ -413,22 +416,14 @@ public String getVersion() { return StringUtils.isEmpty(this.version) ? (provider != null ? provider.getVersion() : this.version) : this.version; } - private void computeValidProtocolIds() { - if (StringUtils.isEmpty(getProtocolIds())) { - if (getProvider() != null && StringUtils.isNotEmpty(getProvider().getProtocolIds())) { - setProtocolIds(getProvider().getProtocolIds()); - } - } - } - @Override protected void computeValidRegistryIds() { - super.computeValidRegistryIds(); - if (StringUtils.isEmpty(getRegistryIds())) { - if (getProvider() != null && StringUtils.isNotEmpty(getProvider().getRegistryIds())) { - setRegistryIds(getProvider().getRegistryIds()); - } + if (provider != null && notHasSelfRegistryProperty()) { + setRegistries(provider.getRegistries()); + setRegistryIds(provider.getRegistryIds()); } + + super.computeValidRegistryIds(); } public abstract void export(); diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java index 6445588c582..7a87c8b4f7c 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ReferenceConfig.java @@ -424,11 +424,6 @@ public void checkAndUpdateSubConfigs() { throw new IllegalStateException(" interface not allow null!"); } completeCompoundConfigs(consumer); - if (consumer != null) { - if (StringUtils.isEmpty(registryIds)) { - setRegistryIds(consumer.getRegistryIds()); - } - } // get consumer's global configuration checkDefault();