From cdb51db4e6d5971b7dd448375bddfe792c5be7b2 Mon Sep 17 00:00:00 2001 From: haoyann <1064645534@qq.com> Date: Wed, 15 Sep 2021 11:45:14 +0800 Subject: [PATCH] Fix circular reference --- .../java/org/apache/dubbo/admin/config/ConfigCenter.java | 9 ++++----- .../admin/registry/mapping/AdminMappingListener.java | 2 -- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/config/ConfigCenter.java b/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/config/ConfigCenter.java index 1f231d972..e2c3e3eb2 100644 --- a/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/config/ConfigCenter.java +++ b/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/config/ConfigCenter.java @@ -22,10 +22,12 @@ import org.apache.dubbo.admin.common.exception.ConfigurationException; import org.apache.dubbo.admin.common.util.Constants; import org.apache.dubbo.admin.registry.config.GovernanceConfiguration; +import org.apache.dubbo.admin.registry.mapping.AdminMappingListener; import org.apache.dubbo.admin.registry.mapping.ServiceMapping; import org.apache.dubbo.admin.registry.mapping.impl.NoOpServiceMapping; import org.apache.dubbo.admin.registry.metadata.MetaDataCollector; import org.apache.dubbo.admin.registry.metadata.impl.NoOpMetadataCollector; +import org.apache.dubbo.admin.service.impl.InstanceRegistryCache; import org.apache.dubbo.common.URL; import org.apache.dubbo.common.config.Environment; import org.apache.dubbo.common.extension.ExtensionLoader; @@ -39,7 +41,6 @@ import org.apache.dubbo.registry.client.ServiceDiscoveryFactory; import org.apache.dubbo.rpc.model.ApplicationModel; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -100,9 +101,6 @@ public class ConfigCenter { private URL registryUrl; private URL metadataUrl; - @Autowired - private MappingListener mappingListener; - /* * generate dynamic configuration client */ @@ -226,11 +224,12 @@ ServiceDiscovery getServiceDiscoveryRegistry() throws Exception { @Bean @DependsOn("metaDataCollector") - ServiceMapping getServiceMapping() { + ServiceMapping getServiceMapping(ServiceDiscovery serviceDiscovery, InstanceRegistryCache instanceRegistryCache) { ServiceMapping serviceMapping = new NoOpServiceMapping(); if (metadataUrl == null) { return serviceMapping; } + MappingListener mappingListener = new AdminMappingListener(serviceDiscovery, instanceRegistryCache); serviceMapping = ExtensionLoader.getExtensionLoader(ServiceMapping.class).getExtension(metadataUrl.getProtocol()); serviceMapping.addMappingListener(mappingListener); serviceMapping.init(metadataUrl); diff --git a/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/registry/mapping/AdminMappingListener.java b/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/registry/mapping/AdminMappingListener.java index 56db6e375..750c7347e 100644 --- a/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/registry/mapping/AdminMappingListener.java +++ b/dubbo-admin-server/src/main/java/org/apache/dubbo/admin/registry/mapping/AdminMappingListener.java @@ -31,7 +31,6 @@ import org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener; import com.google.common.collect.Sets; -import org.springframework.stereotype.Component; import java.util.List; import java.util.Map; @@ -40,7 +39,6 @@ import java.util.concurrent.ConcurrentMap; import java.util.stream.Collectors; -@Component public class AdminMappingListener implements MappingListener { private static final URL CONSUMER_URL = new URL(Constants.ADMIN_PROTOCOL, NetUtils.getLocalHost(), 0, "",