使用vue axios 发送请求,遭遇302跨域问题,在后端处理跨域问题加载实现了webMvcconfigurer 类,并在controller层使用注解@crossOrigin 后仍然无效,求解决方法
参考:
@Override
public void addCorsMappings(CorsRegistry registry) {
/**
* 允许跨域配置
*/
registry.addMapping("/**")
.allowedOrigins("*")
.allowCredentials(true)
.allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD")
.maxAge(3600);
sms = smsService.getById(1);
}
后端的话,一般可以写一个过滤器来处理前端的跨域请求问题
我是这么写的但是没用。错误信息:Access to XMLHttpRequest at 'http://localhost:9002/user/login' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.