/**
* 跨域配置
*/
@WebFilter(urlPatterns = {"/*"})
public class CorsFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest servletRequest = (HttpServletRequest) request;
HttpServletResponse servletResponse = (HttpServletResponse) response;
servletResponse.setHeader("Access-Control-Allow-Origin", servletRequest.getHeader("Origin"));
servletResponse.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,PATCH,OPTIONS");
servletResponse.setHeader("Access-Control-Max-Age", "3600");
servletResponse.setHeader("Access-Control-Allow-Headers", "TOKEN, Origin, X-Requested-With, Content-Type, Accept,Content-Disposition");
servletResponse.addHeader("Access-Control-Allow-Credentials", "true");
chain.doFilter(request, response);
}
}
spring boot项目配置跨域(拦截器)