title: Enabling CORS globally in Spring Boot
body: <p>I tried to enable CORS globally like this: </p>
  
  <pre><code>@Configuration
  @ComponentScan("com.example")
  @EnableWebMvc
  public class OriginFilter extends WebMvcConfigurerAdapter {
  
      @Override
      public void addCorsMappings(CorsRegistry registry) {
          registry.addMapping("/**").allowedMethods("GET", "POST", "PUT", "DELETE");
      }
  }
  </code></pre>
  
  <p>I also tried this approach: </p>
  
  <pre><code>@Configuration
  public class OriginFilter implements WebMvcConfigurer {
  
      @Override
      public void addCorsMappings(CorsRegistry registry) {
          registry.addMapping("/**")
                  .allowedOrigins("*")
                  .allowedMethods("GET", "POST", "PUT", "DELETE", "HEAD")
                  .allowCredentials(true);
      }
  }
  </code></pre>
  
  <p>But none of these worked for me.</p>
  
  <p>An annotation <code>@CrossOrigin</code> for an individual class works, but I wanted to enable CORS it globally. </p>