title: How to do a @CrossOrigin annotation in Spring 3?
body: <p>I'd like to do @CrossOrigin like this:</p>
  
  <pre><code>@CrossOrigin(origins = "http://domain2.com")
  @RequestMapping("/{id}")
  public Account retrieve(@PathVariable Long id) {
      // ...
  }
  </code></pre>
  
  <p>(Assuming upgrading to Spring 4 is constrained) What I have to do at the moment with Spring 3 looks like this:</p>
  
  <pre><code>public class CORSFilter implements Filter {
      public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
          HttpServletResponse response = (HttpServletResponse) res;
          HttpServletRequest request= (HttpServletRequest) req;
          response.setHeader("Access-Control-Allow-Origin", "*");
          response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
          response.setHeader("Access-Control-Allow-Headers", "x-requested-with");
          response.setHeader("Access-Control-Expose-Headers", "x-requested-with"); chain.doFilter(req, res);
      }
  }
  </code></pre>
  
  <p>Note that the source for the implementation of <code>@CrossOrigin</code> in Spring 4.2 <a href="https://github.com/spring-projects/spring-framework/search?utf8=%E2%9C%93&amp;q=CrossOrigin" rel="noreferrer">is here</a>. </p>
  
  <p>My question is: <strong>How to do a @CrossOrigin annotation in Spring 3?</strong></p>