<ul dir="auto">
<li>[ <g-emoji class="g-emoji" alias="white_check_mark" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2705.png">✅</g-emoji>] 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>[<g-emoji class="g-emoji" alias="white_check_mark" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2705.png">✅</g-emoji> ] 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.6.x, tag2.7.1</li>
<li>Operating System version: mac</li>
<li>Java version: jdk1.8</li>
</ul>
<h3 dir="auto">Steps to reproduce this issue</h3>
<ol dir="auto">
<li>run unit test in the source code, ReferenceAnnotationBeanPostProcessorTest#test</li>
<li>then an exception occur</li>
<li><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/reference/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/reference">@reference</a> proxy object needs connect to Service, but at this time Service is not ready.</li>
</ol>
<p dir="auto">this issue is like this one: [https://github.com/<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="316678524" data-permission-text="Title is private" data-url="https://github.com/apache/dubbo/issues/1654" data-hovercard-type="issue" data-hovercard-url="/apache/dubbo/issues/1654/hovercard" href="https://github.com/apache/dubbo/issues/1654">/issues/1654</a>]</p>
<p dir="auto">I run this test on branch 3.x-dev and it is ok. i compare the code between 3.x-dev and 2.6.x</p>
<p dir="auto">there are some differences on this method</p>
<p dir="auto">branch 2.6.x</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="private String buildReferencedBeanName(Reference reference, Class&lt;?&gt; injectedType) {

        AnnotationBeanNameBuilder builder = AnnotationBeanNameBuilder.create(reference, injectedType);
        builder.environment(getEnvironment());
        return getEnvironment().resolvePlaceholders(builder.build());
}"><pre class="notranslate"><code class="notranslate">private String buildReferencedBeanName(Reference reference, Class&lt;?&gt; injectedType) {

        AnnotationBeanNameBuilder builder = AnnotationBeanNameBuilder.create(reference, injectedType);
        builder.environment(getEnvironment());
        return getEnvironment().resolvePlaceholders(builder.build());
}
</code></pre></div>
<p dir="auto">branch 3.x-dev</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="private String buildReferencedBeanName(Reference reference, Class&lt;?&gt; injectedType) {
        ServiceBeanNameBuilder builder = ServiceBeanNameBuilder.create(reference, injectedType, getEnvironment());
        return getEnvironment().resolvePlaceholders(builder.build());
}"><pre class="notranslate"><code class="notranslate">private String buildReferencedBeanName(Reference reference, Class&lt;?&gt; injectedType) {
        ServiceBeanNameBuilder builder = ServiceBeanNameBuilder.create(reference, injectedType, getEnvironment());
        return getEnvironment().resolvePlaceholders(builder.build());
}
</code></pre></div>
<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>
<p dir="auto">unit test run ok.</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="java.lang.IllegalStateException: Failed to load ApplicationContext

	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testBean': Injection of @com.alibaba.dubbo.config.annotation.Reference dependencies is failed; nested exception is com.alibaba.dubbo.rpc.RpcException: Fail to create remoting client for service(dubbo://127.0.0.1:12345/com.alibaba.dubbo.config.spring.api.DemoService?application=dubbo-annotation-provider&amp;codec=dubbo&amp;default.timeout=2000&amp;dubbo=2.0.2&amp;heartbeat=60000&amp;interface=com.alibaba.dubbo.config.spring.api.DemoService&amp;methods=sayName,getBox&amp;owner=world&amp;pid=919&amp;register.ip=10.99.60.252&amp;revision=2.5.7&amp;side=consumer&amp;timestamp=1555913871891&amp;version=2.5.7): client(url: dubbo://127.0.0.1:12345/com.alibaba.dubbo.config.spring.api.DemoService?application=dubbo-annotation-provider&amp;codec=dubbo&amp;default.timeout=2000&amp;dubbo=2.0.2&amp;heartbeat=60000&amp;interface=com.alibaba.dubbo.config.spring.api.DemoService&amp;methods=sayName,getBox&amp;owner=world&amp;pid=919&amp;register.ip=10.99.60.252&amp;revision=2.5.7&amp;side=consumer&amp;timestamp=1555913871891&amp;version=2.5.7) failed to connect to server /127.0.0.1:12345, error message is:Connection refused: /10.99.60.252:12345
	at com.alibaba.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor.postProcessPropertyValues(AnnotationInjectedBeanPostProcessor.java:132)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1268)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:106)
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:249)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
	... 24 more
Caused by: com.alibaba.dubbo.rpc.RpcException: Fail to create remoting client for service(dubbo://127.0.0.1:12345/com.alibaba.dubbo.config.spring.api.DemoService?application=dubbo-annotation-provider&amp;codec=dubbo&amp;default.timeout=2000&amp;dubbo=2.0.2&amp;heartbeat=60000&amp;interface=com.alibaba.dubbo.config.spring.api.DemoService&amp;methods=sayName,getBox&amp;owner=world&amp;pid=919&amp;register.ip=10.99.60.252&amp;revision=2.5.7&amp;side=consumer&amp;timestamp=1555913871891&amp;version=2.5.7): client(url: dubbo://127.0.0.1:12345/com.alibaba.dubbo.config.spring.api.DemoService?application=dubbo-annotation-provider&amp;codec=dubbo&amp;default.timeout=2000&amp;dubbo=2.0.2&amp;heartbeat=60000&amp;interface=com.alibaba.dubbo.config.spring.api.DemoService&amp;methods=sayName,getBox&amp;owner=world&amp;pid=919&amp;register.ip=10.99.60.252&amp;revision=2.5.7&amp;side=consumer&amp;timestamp=1555913871891&amp;version=2.5.7) failed to connect to server /127.0.0.1:12345, error message is:Connection refused: /10.99.60.252:12345
	at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol.initClient(DubboProtocol.java:420)
	at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol.getSharedClient(DubboProtocol.java:384)
	at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol.getClients(DubboProtocol.java:355)
	at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol.refer(DubboProtocol.java:337)
	at com.alibaba.dubbo.rpc.protocol.ProtocolListenerWrapper.refer(ProtocolListenerWrapper.java:67)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper.refer(ProtocolFilterWrapper.java:108)
	at com.alibaba.dubbo.rpc.Protocol$Adaptive.refer(Protocol$Adaptive.java)
	at com.alibaba.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:396)
	at com.alibaba.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:335)
	at com.alibaba.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:164)
	at com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor$ReferenceBeanInvocationHandler.init(ReferenceAnnotationBeanPostProcessor.java:174)
	at com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor$ReferenceBeanInvocationHandler.access$100(ReferenceAnnotationBeanPostProcessor.java:147)
	at com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.buildInvocationHandler(ReferenceAnnotationBeanPostProcessor.java:141)
	at com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.buildProxy(ReferenceAnnotationBeanPostProcessor.java:123)
	at com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.doGetInjectedBean(ReferenceAnnotationBeanPostProcessor.java:117)
	at com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.doGetInjectedBean(ReferenceAnnotationBeanPostProcessor.java:50)
	at com.alibaba.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor.getInjectedObject(AnnotationInjectedBeanPostProcessor.java:340)
	at com.alibaba.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor$AnnotatedFieldElement.inject(AnnotationInjectedBeanPostProcessor.java:520)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
	at com.alibaba.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor.postProcessPropertyValues(AnnotationInjectedBeanPostProcessor.java:128)
	... 40 more
Caused by: com.alibaba.dubbo.remoting.RemotingException: client(url: dubbo://127.0.0.1:12345/com.alibaba.dubbo.config.spring.api.DemoService?application=dubbo-annotation-provider&amp;codec=dubbo&amp;default.timeout=2000&amp;dubbo=2.0.2&amp;heartbeat=60000&amp;interface=com.alibaba.dubbo.config.spring.api.DemoService&amp;methods=sayName,getBox&amp;owner=world&amp;pid=919&amp;register.ip=10.99.60.252&amp;revision=2.5.7&amp;side=consumer&amp;timestamp=1555913871891&amp;version=2.5.7) failed to connect to server /127.0.0.1:12345, error message is:Connection refused: /10.99.60.252:12345
	at com.alibaba.dubbo.remoting.transport.netty4.NettyClient.doConnect(NettyClient.java:127)
	at com.alibaba.dubbo.remoting.transport.AbstractClient.connect(AbstractClient.java:275)
	at com.alibaba.dubbo.remoting.transport.AbstractClient.&lt;init&gt;(AbstractClient.java:89)
	at com.alibaba.dubbo.remoting.transport.netty4.NettyClient.&lt;init&gt;(NettyClient.java:55)
	at com.alibaba.dubbo.remoting.transport.netty4.NettyTransporter.connect(NettyTransporter.java:37)
	at com.alibaba.dubbo.remoting.Transporter$Adaptive.connect(Transporter$Adaptive.java)
	at com.alibaba.dubbo.remoting.Transporters.connect(Transporters.java:75)
	at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchanger.connect(HeaderExchanger.java:39)
	at com.alibaba.dubbo.remoting.exchange.Exchangers.connect(Exchangers.java:109)
	at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol.initClient(DubboProtocol.java:417)
	... 59 more
Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: /10.99.60.252:12345
	at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
	at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
	at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:325)
	at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:635)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:582)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:499)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:461)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.ConnectException: Connection refused
	... 11 more"><pre class="notranslate"><code class="notranslate">java.lang.IllegalStateException: Failed to load ApplicationContext

	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
	at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
	at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
	at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'testBean': Injection of @com.alibaba.dubbo.config.annotation.Reference dependencies is failed; nested exception is com.alibaba.dubbo.rpc.RpcException: Fail to create remoting client for service(dubbo://127.0.0.1:12345/com.alibaba.dubbo.config.spring.api.DemoService?application=dubbo-annotation-provider&amp;codec=dubbo&amp;default.timeout=2000&amp;dubbo=2.0.2&amp;heartbeat=60000&amp;interface=com.alibaba.dubbo.config.spring.api.DemoService&amp;methods=sayName,getBox&amp;owner=world&amp;pid=919&amp;register.ip=10.99.60.252&amp;revision=2.5.7&amp;side=consumer&amp;timestamp=1555913871891&amp;version=2.5.7): client(url: dubbo://127.0.0.1:12345/com.alibaba.dubbo.config.spring.api.DemoService?application=dubbo-annotation-provider&amp;codec=dubbo&amp;default.timeout=2000&amp;dubbo=2.0.2&amp;heartbeat=60000&amp;interface=com.alibaba.dubbo.config.spring.api.DemoService&amp;methods=sayName,getBox&amp;owner=world&amp;pid=919&amp;register.ip=10.99.60.252&amp;revision=2.5.7&amp;side=consumer&amp;timestamp=1555913871891&amp;version=2.5.7) failed to connect to server /127.0.0.1:12345, error message is:Connection refused: /10.99.60.252:12345
	at com.alibaba.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor.postProcessPropertyValues(AnnotationInjectedBeanPostProcessor.java:132)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1268)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:312)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:308)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:128)
	at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:106)
	at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:249)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
	at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
	... 24 more
Caused by: com.alibaba.dubbo.rpc.RpcException: Fail to create remoting client for service(dubbo://127.0.0.1:12345/com.alibaba.dubbo.config.spring.api.DemoService?application=dubbo-annotation-provider&amp;codec=dubbo&amp;default.timeout=2000&amp;dubbo=2.0.2&amp;heartbeat=60000&amp;interface=com.alibaba.dubbo.config.spring.api.DemoService&amp;methods=sayName,getBox&amp;owner=world&amp;pid=919&amp;register.ip=10.99.60.252&amp;revision=2.5.7&amp;side=consumer&amp;timestamp=1555913871891&amp;version=2.5.7): client(url: dubbo://127.0.0.1:12345/com.alibaba.dubbo.config.spring.api.DemoService?application=dubbo-annotation-provider&amp;codec=dubbo&amp;default.timeout=2000&amp;dubbo=2.0.2&amp;heartbeat=60000&amp;interface=com.alibaba.dubbo.config.spring.api.DemoService&amp;methods=sayName,getBox&amp;owner=world&amp;pid=919&amp;register.ip=10.99.60.252&amp;revision=2.5.7&amp;side=consumer&amp;timestamp=1555913871891&amp;version=2.5.7) failed to connect to server /127.0.0.1:12345, error message is:Connection refused: /10.99.60.252:12345
	at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol.initClient(DubboProtocol.java:420)
	at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol.getSharedClient(DubboProtocol.java:384)
	at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol.getClients(DubboProtocol.java:355)
	at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol.refer(DubboProtocol.java:337)
	at com.alibaba.dubbo.rpc.protocol.ProtocolListenerWrapper.refer(ProtocolListenerWrapper.java:67)
	at com.alibaba.dubbo.rpc.protocol.ProtocolFilterWrapper.refer(ProtocolFilterWrapper.java:108)
	at com.alibaba.dubbo.rpc.Protocol$Adaptive.refer(Protocol$Adaptive.java)
	at com.alibaba.dubbo.config.ReferenceConfig.createProxy(ReferenceConfig.java:396)
	at com.alibaba.dubbo.config.ReferenceConfig.init(ReferenceConfig.java:335)
	at com.alibaba.dubbo.config.ReferenceConfig.get(ReferenceConfig.java:164)
	at com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor$ReferenceBeanInvocationHandler.init(ReferenceAnnotationBeanPostProcessor.java:174)
	at com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor$ReferenceBeanInvocationHandler.access$100(ReferenceAnnotationBeanPostProcessor.java:147)
	at com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.buildInvocationHandler(ReferenceAnnotationBeanPostProcessor.java:141)
	at com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.buildProxy(ReferenceAnnotationBeanPostProcessor.java:123)
	at com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.doGetInjectedBean(ReferenceAnnotationBeanPostProcessor.java:117)
	at com.alibaba.dubbo.config.spring.beans.factory.annotation.ReferenceAnnotationBeanPostProcessor.doGetInjectedBean(ReferenceAnnotationBeanPostProcessor.java:50)
	at com.alibaba.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor.getInjectedObject(AnnotationInjectedBeanPostProcessor.java:340)
	at com.alibaba.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor$AnnotatedFieldElement.inject(AnnotationInjectedBeanPostProcessor.java:520)
	at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
	at com.alibaba.dubbo.config.spring.beans.factory.annotation.AnnotationInjectedBeanPostProcessor.postProcessPropertyValues(AnnotationInjectedBeanPostProcessor.java:128)
	... 40 more
Caused by: com.alibaba.dubbo.remoting.RemotingException: client(url: dubbo://127.0.0.1:12345/com.alibaba.dubbo.config.spring.api.DemoService?application=dubbo-annotation-provider&amp;codec=dubbo&amp;default.timeout=2000&amp;dubbo=2.0.2&amp;heartbeat=60000&amp;interface=com.alibaba.dubbo.config.spring.api.DemoService&amp;methods=sayName,getBox&amp;owner=world&amp;pid=919&amp;register.ip=10.99.60.252&amp;revision=2.5.7&amp;side=consumer&amp;timestamp=1555913871891&amp;version=2.5.7) failed to connect to server /127.0.0.1:12345, error message is:Connection refused: /10.99.60.252:12345
	at com.alibaba.dubbo.remoting.transport.netty4.NettyClient.doConnect(NettyClient.java:127)
	at com.alibaba.dubbo.remoting.transport.AbstractClient.connect(AbstractClient.java:275)
	at com.alibaba.dubbo.remoting.transport.AbstractClient.&lt;init&gt;(AbstractClient.java:89)
	at com.alibaba.dubbo.remoting.transport.netty4.NettyClient.&lt;init&gt;(NettyClient.java:55)
	at com.alibaba.dubbo.remoting.transport.netty4.NettyTransporter.connect(NettyTransporter.java:37)
	at com.alibaba.dubbo.remoting.Transporter$Adaptive.connect(Transporter$Adaptive.java)
	at com.alibaba.dubbo.remoting.Transporters.connect(Transporters.java:75)
	at com.alibaba.dubbo.remoting.exchange.support.header.HeaderExchanger.connect(HeaderExchanger.java:39)
	at com.alibaba.dubbo.remoting.exchange.Exchangers.connect(Exchangers.java:109)
	at com.alibaba.dubbo.rpc.protocol.dubbo.DubboProtocol.initClient(DubboProtocol.java:417)
	... 59 more
Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: /10.99.60.252:12345
	at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
	at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
	at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:325)
	at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:340)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:635)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:582)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:499)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:461)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884)
	at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.ConnectException: Connection refused
	... 11 more
</code></pre></div>
<ul dir="auto">
<li>[ * ] 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>[ * ] 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.7</li>
<li>Operating System version: CentOS 7</li>
<li>Java version: 1.8.0_202</li>
</ul>
<h3 dir="auto">Steps to reproduce this issue</h3>
<p dir="auto">Code to reproduce: <a href="https://github.com/seraphain/dubbo-thread-leak">https://github.com/seraphain/dubbo-thread-leak</a></p>
<ol dir="auto">
<li>Start a zookeeper on 127.0.0.1:2181.</li>
<li>Run com.github.seraphain.demo.dubbo.Server. Before the server exits, run com.github.seraphain.demo.dubbo.Client.</li>
<li>Use jps to get client pid: jps | grep Client.</li>
<li>Use jstack to get dubbo threads number: jstack -l [pid] | grep Dubbo | wc -l. The result is 50 or 51.</li>
<li>After the server exits, run com.github.seraphain.demo.dubbo.Server again.</li>
<li>Use jstack to get dubbo thread number: jstack -l [pid] | grep Dubbo | wc -l. The result is 100 or 101.</li>
<li>Repeat step 5 &amp; 6, dubbo thread number keep increasing everytime the server start.</li>
</ol>
<h3 dir="auto">Expected Result</h3>
<p dir="auto">Client dubbo thread number do not increase.</p>
<h3 dir="auto">Actual Result</h3>
<p dir="auto">Client dubbo thread number keep increasing everytime the server start.</p>