title: Enable Cors using Spring 3.0.4
body: <p>I'm using Java Spring 3.0.4 (can't upgrade due to some requirements) and I need to enable Cors in order for my front-end to talk to my back-end.</p>
  
  <p>My back-end is an angular application running on: <a href="http://localhost:4200/home" rel="nofollow noreferrer">http://localhost:4200/home</a></p>
  
  <p>I have tried the following with no luck:</p>
  
  <pre><code>public static final String CREDENTIALS_NAME = "Access-Control-Allow-Credentials";
  public static final String ORIGIN_NAME = "Access-Control-Allow-Origin";
  public static final String METHODS_NAME = "Access-Control-Allow-Methods";
  public static final String HEADERS_NAME = "Access-Control-Allow-Headers";
  public static final String MAX_AGE_NAME = "Access-Control-Max-Age";
  
  @PreAuthorize("hasRole('ADMIN')")
  @RequestMapping(value="/data", method=RequestMethod.GET)
  public void serverSide(Model model,  HttpServletRequest request, HttpServletResponse response) throws IOException{
  
      response.setContentType("application/json");
      response.setHeader("Cache-Control", "no-store");
  
      response.setHeader(CREDENTIALS_NAME, "true");
      response.setHeader(ORIGIN_NAME, "http://localhost:4200");
      response.setHeader(METHODS_NAME, "GET, OPTIONS, POST, PUT, DELETE");
      response.setHeader(HEADERS_NAME, "Origin, X-Requested-With, Content-Type, Accept");
      response.setHeader(MAX_AGE_NAME, "3600");
  
      PrintWriter out = response.getWriter();
  
      out.print("TEST!!");
  }       
  </code></pre>