Tôi muốn làm @CrossOrigin như thế này:Cách thực hiện chú thích @CrossOrigin trong Mùa xuân 3?
@CrossOrigin(origins = "http://domain2.com")
@RequestMapping("/{id}")
public Account retrieve(@PathVariable Long id) {
// ...
}
(Giả sử nâng cấp lên mùa xuân 4 bị hạn chế) Những gì tôi phải làm vào lúc với mùa xuân 3 trông như thế này:
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);
}
}
Lưu ý rằng nguồn để thực hiện @CrossOrigin
trong Mùa xuân 4.2 is here.
Câu hỏi của tôi là: Cách thực hiện chú thích @CrossOrigin trong Spring 3?
Ông có thể chỉ cho tôi một ví dụ HandlerInterceptor tương tự? (Tôi giả sử nó sẽ hoạt động như một chú giải) – hawkeye
@hawkeye Bạn sẽ phải tự mình kiểm tra và giải thích chú thích. Khuyến nghị của tôi là xem xét nguồn Spring 4.2. – chrylis