<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/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/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.8</li>
<li>Operating System version: Ubuntu 20.04</li>
<li>Java version: openjdk 1.8.0_265</li>
</ul>
<h3 dir="auto">Steps to reproduce this issue</h3>
<ol dir="auto">
<li>create a rest service</li>
<li>configure dubbo service as rest via servlet</li>
<li>create junit test with annotation</li>
<li>run junit tests, the first junit test will fail but the following tests run fine.</li>
</ol>
<p dir="auto">Pls. provide [GitHub address] to reproduce this issue.<br>
<a href="https://github.com/abelli85/meterEff/blob/master/meff/src/test/kotlin/com/abel/bigwater/impl/CodeServiceImplTest.kt">https://github.com/abelli85/meterEff/blob/master/meff/src/test/kotlin/com/abel/bigwater/impl/CodeServiceImplTest.kt</a></p>
<h3 dir="auto">Expected Result</h3>
<p dir="auto">configuration for dubbo-rest via servlet:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;dubbo:protocol name=&quot;rest&quot; port=&quot;8080&quot; threads=&quot;500&quot; contextpath=&quot;meff&quot; server=&quot;servlet&quot; accepts=&quot;500&quot;
..."><pre class="notranslate"><code class="notranslate">&lt;dubbo:protocol name="rest" port="8080" threads="500" contextpath="meff" server="servlet" accepts="500"
...
</code></pre></div>
<p dir="auto">here's junit test class:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="// create junit test class with annotation
@ContextConfiguration(locations = [&quot;classpath:/spring/rest-provider.xml&quot;, &quot;classpath:/spring-mybatis.xml&quot;])
@RunWith(SpringJUnit4ClassRunner::class)
class CodeServiceImplTest {
  @Test
  fun test1() {
    // ...
  }
  
  @Test
  fun test2() {
    //...
  }
..."><pre class="notranslate"><code class="notranslate">// create junit test class with annotation
@ContextConfiguration(locations = ["classpath:/spring/rest-provider.xml", "classpath:/spring-mybatis.xml"])
@RunWith(SpringJUnit4ClassRunner::class)
class CodeServiceImplTest {
  @Test
  fun test1() {
    // ...
  }
  
  @Test
  fun test2() {
    //...
  }
...
</code></pre></div>
<p dir="auto">What do you expected from the above steps？<br>
all junit tests including the first SHOULD run fine.</p>
<h3 dir="auto">Actual Result</h3>
<p dir="auto">What actually happens?<br>
the first junit test in the list always FAILS.</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!
Caused by: org.apache.dubbo.rpc.RpcException: No servlet context found. If you are using server='servlet', make sure that you've configured org.apache.dubbo.remoting.http.servlet.BootstrapListener in web.xml
	at org.apache.dubbo.rpc.protocol.rest.DubboHttpProtocolServer.doStart(DubboHttpProtocolServer.java:62)"><pre class="notranslate"><code class="notranslate">Just put your stack trace here!
Caused by: org.apache.dubbo.rpc.RpcException: No servlet context found. If you are using server='servlet', make sure that you've configured org.apache.dubbo.remoting.http.servlet.BootstrapListener in web.xml
	at org.apache.dubbo.rpc.protocol.rest.DubboHttpProtocolServer.doStart(DubboHttpProtocolServer.java:62)
</code></pre></div>
<h3 dir="auto">Comments:</h3>
<p dir="auto">seems that <strong>web.xml</strong> is loaded lazily during junit tests, so first junit test fails.</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: xxx</li>
<li>Operating System version: xxx</li>
<li>Java version: xxx</li>
</ul>
<h3 dir="auto">Steps to reproduce this issue</h3>
<ol dir="auto">
<li>xxx</li>
<li>xxx</li>
<li>xxx</li>
</ol>
<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>