码迷,mamicode.com
首页 > 编程语言 > 详细

spring boot 配置跨域

时间:2019-01-07 17:27:21      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:lte   max   class   head   work   header   com   Servle   content   

spring boot 跨域

import org.springframework.stereotype.Component;

import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
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,Content-Type,token");
        chain.doFilter(req, res);
    }
    public void init(FilterConfig filterConfig) {}
    public void destroy() {}

}

spring boot 配置跨域

标签:lte   max   class   head   work   header   com   Servle   content   

原文地址:https://www.cnblogs.com/AngeLeyes/p/10233847.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!