spring boot 跨域问题

public class WebMvcConfig implements WebMvcConfigurer {

 @Override  public void addInterceptors(InterceptorRegistry registry) {   registry.addInterceptor(new CorsInterceptor());  }

 

 

//添加interceptor

public class CorsInterceptor extends HandlerInterceptorAdapter {

 @Override  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)    throws Exception {   // 添加跨域CORS   // log.info("---------拦截请求----------");   response.setHeader("Access-Control-Allow-Origin", "*");   response.setHeader("Access-Control-Allow-Headers", "*");   response.setHeader("Access-Control-Allow-Methods", "*");         return true;  } }

posted on 2019-01-16 17:08  corecible  阅读(84)  评论(0编辑  收藏  举报

导航