我想像这样做@CrossOrigin:
@CrossOrigin(origins = "http://domain2.com") @RequestMapping("/{id}") public Account retrieve(@PathVariable Long id) { // ... }
(假设升级到Spring 4受到限制)目前我在Spring 3中所要做的就是这样:
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); } }
请注意,@CrossOrigin
Spring 4.2中的实现源是在这里.
我的问题是:如何在Spring 3中进行@CrossOrigin注释?