<p dir="auto">For a distributed application,  timeout configuration is important. But for many cases, timeout is not easy to determine.</p>
<p dir="auto">For example,  a client calls a remote service service A , and A's method calls Service B and C and D in sequence. When the client set a timeout of 3s, for a good practice, B and C as well as D should not cost more than 3 seconds. However, if I set timeout of B, C and D  to 3000ms. what if B cost 2000ms to return, and C cost 2000ms to return, these two service has been already cost 4 seconds, no matter how fast D is, it is a waste for many cases.</p>
<p dir="auto">In a word, it is very hard to set a small enough and reasonable value for many cases. What if Dubbo provide a smart timeout?</p>
<p dir="auto">Again, we use the same case above. when B returns, it takes 2s, and dubbo modify the timeout to a value less than 1s(consider other cost that in the same context), then go calling C. In this case C takes 2 seconds, it must timeout.  then D will not be called.</p>
<p dir="auto">I was trying to do this in dubbo filler, but in current implementation, timeout is not about to modify since it is from the url instead of attachment.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="int timeout = getUrl().getMethodPositiveParameter(methodName, TIMEOUT_KEY, DEFAULT_TIMEOUT);"><pre class="notranslate"><code class="notranslate">int timeout = getUrl().getMethodPositiveParameter(methodName, TIMEOUT_KEY, DEFAULT_TIMEOUT);
</code></pre></div>
<p dir="auto">So user cannot even implement this feature in dubbo filter in their own.</p>
<p dir="auto">If Bean Class annotated <code class="notranslate">@Service</code> and Dubbo's <code class="notranslate">@com.alibaba.dubbo.config.annotation.Service</code>,<br>
and <code class="notranslate">@DubboComponentScan</code> and <code class="notranslate">@ComponentScan</code> were present on <code class="notranslate">@Configuration</code> Class, the Spring Context will scan this component twice.</p>
<p dir="auto">Test cases:</p>
<h2 dir="auto">Test Configuration Class</h2>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@EnableDubbo(scanBasePackages = &quot;com.alibaba.dubbo.config.spring.context.annotation&quot;)
@ComponentScan(basePackages = &quot;com.alibaba.dubbo.config.spring.context.annotation&quot;)
@PropertySource(&quot;META-INF/dubbb-provider.properties&quot;)
@EnableTransactionManagement
public static class TestProviderConfiguration {
}"><pre class="notranslate"><span class="pl-c1">@</span><span class="pl-c1">EnableDubbo</span>(<span class="pl-s1">scanBasePackages</span> = <span class="pl-s">"com.alibaba.dubbo.config.spring.context.annotation"</span>)
<span class="pl-c1">@</span><span class="pl-c1">ComponentScan</span>(<span class="pl-s1">basePackages</span> = <span class="pl-s">"com.alibaba.dubbo.config.spring.context.annotation"</span>)
<span class="pl-c1">@</span><span class="pl-c1">PropertySource</span>(<span class="pl-s">"META-INF/dubbb-provider.properties"</span>)
<span class="pl-c1">@</span><span class="pl-c1">EnableTransactionManagement</span>
<span class="pl-k">public</span> <span class="pl-k">static</span> <span class="pl-k">class</span> <span class="pl-smi">TestProviderConfiguration</span> {
}</pre></div>
<h2 dir="auto">Service Class</h2>
<div class="highlight highlight-source-java notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@com.alibaba.dubbo.config.annotation.Service(
        version = &quot;2.5.7&quot;,
        application = &quot;${demo.service.application}&quot;,
        protocol = &quot;${demo.service.protocol}&quot;,
        registry = &quot;${demo.service.registry}&quot;
)
@Service
@Transactional
public class DemoServiceImpl implements DemoService {

    @Override
    public String sayName(String name) {
        return &quot;Hello,&quot; + name;
    }

    @Override
    public Box getBox() {
        return new Box() {
            @Override
            public String getName() {
                return &quot;MyBox&quot;;
            }
        };
    }
}"><pre class="notranslate"><span class="pl-c1">@</span><span class="pl-s1">com</span>.<span class="pl-s1">alibaba</span>.<span class="pl-s1">dubbo</span>.<span class="pl-s1">config</span>.<span class="pl-s1">annotation</span>.<span class="pl-s1">Service</span>(
        <span class="pl-s1">version</span> = <span class="pl-s">"2.5.7"</span>,
        <span class="pl-s1">application</span> = <span class="pl-s">"${demo.service.application}"</span>,
        <span class="pl-s1">protocol</span> = <span class="pl-s">"${demo.service.protocol}"</span>,
        <span class="pl-s1">registry</span> = <span class="pl-s">"${demo.service.registry}"</span>
)
<span class="pl-c1">@</span><span class="pl-c1">Service</span>
<span class="pl-c1">@</span><span class="pl-c1">Transactional</span>
<span class="pl-k">public</span> <span class="pl-k">class</span> <span class="pl-smi">DemoServiceImpl</span> <span class="pl-k">implements</span> <span class="pl-smi">DemoService</span> {

    <span class="pl-c1">@</span><span class="pl-c1">Override</span>
    <span class="pl-k">public</span> <span class="pl-smi">String</span> <span class="pl-en">sayName</span>(<span class="pl-smi">String</span> <span class="pl-s1">name</span>) {
        <span class="pl-k">return</span> <span class="pl-s">"Hello,"</span> + <span class="pl-s1">name</span>;
    }

    <span class="pl-c1">@</span><span class="pl-c1">Override</span>
    <span class="pl-k">public</span> <span class="pl-smi">Box</span> <span class="pl-en">getBox</span>() {
        <span class="pl-k">return</span> <span class="pl-k">new</span> <span class="pl-smi">Box</span>() {
            <span class="pl-c1">@</span><span class="pl-c1">Override</span>
            <span class="pl-k">public</span> <span class="pl-smi">String</span> <span class="pl-en">getName</span>() {
                <span class="pl-k">return</span> <span class="pl-s">"MyBox"</span>;
            }
        };
    }
}</pre></div>