title: No 'Access-Control-Allow-Origin' header is present on the requested resource. Ionic, AngularJS, Spring Boot 1.3
body: <p>I am using Ionic and Spring Boot 1.3. It wasn't until I upgraded to 1.3 that I am getting this problem...</p>
  
  <p>Apparently after updating to Spring Boot 1.3. CorsFilter is being ignored completely. All this deprecation is driving me nuts. So I looked up the NEW way and this is what I got.</p>
  
  <pre><code>package app.config;
  
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.servlet.config.annotation.CorsRegistry;
  import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
  
  @Configuration
  @EnableWebMvc
  public class WebConfig extends WebMvcConfigurerAdapter {
  
      @Override
      public void addCorsMappings(CorsRegistry registry) {
          registry.addMapping("/**")
                  .allowedOrigins("http://192.168.1.66:8101")
                  .allowCredentials(false)
                  .maxAge(3600)
                  .allowedHeaders("Accept", "Content-Type", "Origin", "Authorization", "X-Auth-Token")
                  .exposedHeaders("X-Auth-Token", "Authorization")
                  .allowedMethods("POST", "GET", "DELETE", "PUT", "OPTIONS");
      }
  }
  </code></pre>
  
  <p>The above piece of code is excuted on the boot of the application. Unlike CorsFilter that is executed every time there is a request. But switching to Spring Boot 1.3, I can no longer get this in the chain filter.</p>
  
  <p>Again, the code is being loaded, I set a break point and addCorsMapping is called every time so the settings are being made. So.... Why am I still getting this error</p>
  
  <pre><code>XMLHttpRequest cannot load http://192.168.1.66:8080/login?username=billyjoe&amp;password=happy. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://192.168.1.66:8101' is therefore not allowed access.
  </code></pre>
  
  <p><strong>EDIT</strong>
  Below is my old CorsFilter. It no longer works since I updated to Spring Boot 1.3</p>
  
  <pre><code>package app.config;
  
  import java.io.IOException;
  import javax.servlet.Filter;
  import javax.servlet.FilterChain;
  import javax.servlet.FilterConfig;
  import javax.servlet.ServletException;
  import javax.servlet.ServletRequest;
  import javax.servlet.ServletResponse;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  import org.springframework.stereotype.Component;
  
  @Component
  public class CorsFilter implements Filter {
  
      private final Logger log = LoggerFactory.getLogger(CorsFilter.class);
  
      public CorsFilter() {
          log.info("SimpleCORSFilter init");
      }
  
      @Override
      public void doFilter(ServletRequest req,
                           ServletResponse res,
                           FilterChain chain) throws IOException, ServletException {
  
          HttpServletRequest request = (HttpServletRequest) req;
          HttpServletResponse response = (HttpServletResponse) res;
          String clientOrigin = request.getHeader("origin");
          response.addHeader("Access-Control-Allow-Origin", clientOrigin);
          response.setHeader("Access-Control-Allow-Methods", "POST, GET,  DELETE, PUT");
          response.setHeader("Access-Control-Allow-Credentials", "true");
          response.setHeader("Access-Control-Max-Age", "3600");
          response.setHeader("Access-Control-Allow-Headers", "Accept, Content-Type, Origin, Authorization, X-Auth-Token");
          response.addHeader("Access-Control-Expose-Headers", "X-Auth-Token");
  
          if (request.getMethod().equals("OPTIONS")) {
              response.setStatus(HttpServletResponse.SC_OK);
          } else {
              chain.doFilter(request, response);
          }
      }
  
      @Override
      public void init(FilterConfig filterConfig) {
      }
  
      @Override
      public void destroy() {
      }
  
  }
  </code></pre>