<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/apache/incubator-dubbo/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/apache/incubator-dubbo/blob/master/FAQ.md">FAQ</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Dubbo version: 2.7.1</li>
<li>Operating System version: mac sierra 10.12</li>
<li>Java version: 1.8</li>
</ul>
<h3 dir="auto">Steps to reproduce this issue</h3>
<p dir="auto">For PR: <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="444367090" data-permission-text="Title is private" data-url="https://github.com/apache/dubbo/issues/4067" data-hovercard-type="pull_request" data-hovercard-url="/apache/dubbo/pull/4067/hovercard" href="https://github.com/apache/dubbo/pull/4067">#4067</a></p>
<ol dir="auto">
<li>Run consumer without provider as below, it throws No provider exception.</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ReferenceConfigCache cache = ReferenceConfigCache.getCache();
DemoService demoService = (DemoService) cache.get(reference);
demoService.sayHello(&quot;hi&quot;);"><pre class="notranslate"><code class="notranslate">ReferenceConfigCache cache = ReferenceConfigCache.getCache();
DemoService demoService = (DemoService) cache.get(reference);
demoService.sayHello("hi");
</code></pre></div>
<ol start="2" dir="auto">
<li>Start provider and then run consumer again, get null from the demoService.</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ReferenceConfigCache cache = ReferenceConfigCache.getCache();
DemoService demoService = (DemoService) cache.get(reference);"><pre class="notranslate"><code class="notranslate">ReferenceConfigCache cache = ReferenceConfigCache.getCache();
DemoService demoService = (DemoService) cache.get(reference);
</code></pre></div>
<p dir="auto">Pls. provide [GitHub address] to reproduce this issue.</p>
<h3 dir="auto">Expected Result</h3>
<p dir="auto">DemoService should be initialized.</p>
<h3 dir="auto">Actual Result</h3>
<p dir="auto">DemoService returns null even with provider started.</p>
<p dir="auto">For the first time, the ReferenceConfig init throws exception from refprotocol.refer(interfaceClass, urls.get(0)), have not changed the initialized to false. For the second time, the ReferenceConfig cannot init it again as initialized is true.</p>
<p dir="auto">We should set initialized after init finished.</p>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have searched the <a href="https://github.com/apache/dubbo/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> I have checked the <a href="https://github.com/apache/dubbo/blob/master/FAQ.md">FAQ</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Dubbo version: 2.7.3</li>
<li>Operating System version: mac</li>
<li>Java version: jdk 8</li>
</ul>
<h3 dir="auto">Steps to reproduce this issue</h3>
<p dir="auto">注册了两个配置中心，一个用的是dubbo默认配置</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="dubbo.registry.address=zookeeper://127.0.0.1:2181"><pre class="notranslate"><code class="notranslate">dubbo.registry.address=zookeeper://127.0.0.1:2181
</code></pre></div>
<p dir="auto">然后自定一个注册中心:</p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    @Bean
    public RegistryConfig ecareConsumerConfig() {
        RegistryConfig registryConfig = new RegistryConfig();
        registryConfig.setAddress(&quot;zookeeper://127.0.0.1:2182&quot;);
        registryConfig.setGroup(&quot;dubbo&quot;);
        return registryConfig;
    }"><pre class="notranslate">    <span class="pl-c1">@</span><span class="pl-c1">Bean</span>
    <span class="pl-k">public</span> <span class="pl-smi">RegistryConfig</span> <span class="pl-s1">ecareConsumerConfig</span>() {
        <span class="pl-smi">RegistryConfig</span> <span class="pl-s1">registryConfig</span> = <span class="pl-k">new</span> <span class="pl-smi">RegistryConfig</span>();
        <span class="pl-s1">registryConfig</span>.<span class="pl-en">setAddress</span>(<span class="pl-s">"zookeeper://127.0.0.1:2182"</span>);
        <span class="pl-s1">registryConfig</span>.<span class="pl-en">setGroup</span>(<span class="pl-s">"dubbo"</span>);
        <span class="pl-k">return</span> <span class="pl-s1">registryConfig</span>;
    }</pre></div>
<p dir="auto">引用时，指定了注册中心<code class="notranslate">ecareConsumerConfig</code></p>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    @Reference(registry = &quot;ecareConsumerConfig&quot;)
    private UserInfoApiService userInfoApiService;"><pre class="notranslate">    <span class="pl-c1">@</span><span class="pl-c1">Reference</span>(<span class="pl-s1">registry</span> = <span class="pl-s">"ecareConsumerConfig"</span>)
    <span class="pl-k">private</span> <span class="pl-smi">UserInfoApiService</span> <span class="pl-s1">userInfoApiService</span>;</pre></div>
<p dir="auto">然后程序启动解析时，源码走到<code class="notranslate">org.apache.dubbo.config.ReferenceConfig.init()</code>里面注册信息都是<code class="notranslate">127.0.0.1:2182</code>，继续走，当走到<code class="notranslate">startConfigCenter</code>里面调用了<code class="notranslate">ConfigManager.getInstance().refreshAll();</code>里面的<code class="notranslate">AbstractConfig.refresh()</code>不管你是否拥有值，都将里面的值覆盖掉，变成<code class="notranslate">zookeeper://127.0.0.1:2181</code>。导致注册中心找错</p>
<p dir="auto">Pls. provide [GitHub address] to reproduce this issue.</p>
<h3 dir="auto">Expected Result</h3>
<p dir="auto">What do you expected from the above steps？</p>
<h3 dir="auto">Actual Result</h3>
<p dir="auto">What actually happens?</p>
<p dir="auto">If there is an exception, please attach the exception trace:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Just put your stack trace here!"><pre class="notranslate"><code class="notranslate">Just put your stack trace here!
</code></pre></div>