title: cors not working for my spring boot application
body: <p>Here is my webConfig</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  public class WebConfig extends WebMvcConfigurerAdapter {
  
      @Override
      public void addCorsMappings(CorsRegistry registry) {
          registry.addMapping("/**");
      }
  }
  </code></pre>
  
  <p>I have a <code>/health</code> endpoint, which returns some health data and it works fine.</p>
  
  <p>Here is junit test</p>
  
  <pre><code>@Test
      public void corsTest() {
          HttpHeaders headers = new HttpHeaders();
          headers.add(HttpHeaders.ORIGIN, "http://localhost:9000");
          HttpEntity&lt;?&gt; requestEntity = new HttpEntity(headers);
          ResponseEntity&lt;Status&gt; entity = this.restTemplate.exchange("/health", HttpMethod.GET, requestEntity, Status.class);
          assertEquals(HttpStatus.OK, entity.getStatusCode());
          assertEquals("http://localhost:9000", entity.getHeaders().getAccessControlAllowOrigin()); //6
          Status health = entity.getBody();
          assertThat(health.getAppName()).isEqualTo(appName);
      }
  </code></pre>
  
  <p>Test fails at line 6. if comment-out that line, the test passes.
  Through debugger, I found that <code>entity.getHeaders().getAccessControlAllowOrigin()</code> is null. I used this <a href="https://github.com/spring-guides/gs-rest-service-cors/blob/master/complete/src/test/java/hello/GreetingIntegrationTests.java" rel="noreferrer">sample app</a> as reference and it works fine. but for my application it fails.</p>
  
  <p>when I use javascript to call the /health api, I can see the cors works. If I comment out, webConfig class, I get error in javascript. Debugging more at javascript shows that cors response header is not set but the request served successfully when webconfig is enabled.</p>
  
  <p>so definitely cors works. It is the test that is failing. so I am guessing test is not seeing it for reasons I don't know.</p>