title: CORS issue with Spring Boot
body: <p>I have a Spring Boot application running on port 8443, and an angular2 based front end on port 8080. I need my front end to make requests to my Spring server, but I'm getting CORS errors left and right. I have added the <code>@CrossOrigin</code> annotation to my RestController method, and I have added a CORSFilter to my project, and mapped it on <code>web.xml</code>, but on Firefox 46.0a2 I still get this error on the console:</p>
  
  <blockquote>
    <p>Cross-Origin Request Blocked: The Same Origin Policy disallows reading
    the remote resource at <a href="https://localhost:8443/allEquips" rel="noreferrer">https://localhost:8443/allEquips</a>. (Reason: CORS
    header 'Access-Control-Allow-Origin' missing).</p>
  </blockquote>
  
  <p>The relevant part of my controller:</p>
  
  <pre><code>@CrossOrigin
  @RequestMapping("/allequips")
  List&lt;String&gt; allequips(Model model) {
      List&lt;String&gt; codes = equipmentRepository.findAllEquipments();
      return codes;
  }
  </code></pre>
  
  <p>The CORSFilter:</p>
  
  <pre><code>public class CORSFilter implements Filter{
       public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
              HttpServletResponse response = (HttpServletResponse) res;
              response.setHeader("Access-Control-Allow-Origin", "*");
              response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
              response.setHeader("Access-Control-Max-Age", "3600");
              response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
              chain.doFilter(req, res);
          }
          public void init(FilterConfig filterConfig) {}
          public void destroy() {}
  }
  </code></pre>
  
  <p>The mapping on <code>web.xml</code>:</p>
  
  <pre><code>  &lt;filter&gt;
    &lt;filter-name&gt;cors&lt;/filter-name&gt;
    &lt;filter-class&gt;config.CORSFilter&lt;/filter-class&gt;
  &lt;/filter&gt;
  &lt;filter-mapping&gt;
    &lt;filter-name&gt;cors&lt;/filter-name&gt;
    &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  </code></pre>
  
  <p>And I don't know if this is important, but the Angular2 code that's making the http request:</p>
  
  <pre><code>@Injectable()
  export class EquipService {
      equips: Array&lt;Equip&gt;;
  
      constructor(public http: Http) {
          console.log('Equip service created.', http);
      }
  
      getEquips() {
          return this.http.get(WebServiceEndPoint+'allEquips')
          .map((responseData) =&gt; {
              return responseData.json();
          }).map((equips: Array&lt;any&gt;) =&gt; {
              let result: Array&lt;Equip&gt; = [];
              if(equips) {
                  equips.forEach((equip) =&gt; {
                      result.push(new Equip(equip.code));
                  });
              }
              return result;
          }).subscribe( res =&gt; this.equips = res);
      }
  }
  </code></pre>
  
  <p>Am I missing some configuration? Is my code wrong in any way?</p>
  
  <p><strong>EDIT:</strong> I gave up and restarted from a previous commit. After that, simply adding <code>@Cross-Origin</code> was enough.</p>