又见跨域大坑....
报错信息如下
"code": 100, "message": "When allowCredentials is true, allowedOrigins cannot contain the special value \"*\"since that cannot be set on the \"Access-Control-Allow-Origin\" response header. To allow credentials to a set of origins, list them explicitly or consider using \"allowedOriginPatterns\" instead."
按照之前的配置,但是很意外,出现了错误,配置好像没生效的样子…
看着报错信息,核心就是allowedOriginPatterns 没错了,所以就跟着多配了一个allowedOriginPatterns("*") 但是还是报错!?? 不对啊 理论上应该好了才对啊,于是再看配置文件,喔~ 下面这样才对 把allowedOrigins注释掉就好啦~
@Configuration public class CrossConfiger implements WebMvcConfigurer{ @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") // .allowedOrigins("*") // 可跨域的域名 .allowCredentials(true) .allowedMethods("*") .allowedHeaders("*") .allowedOriginPatterns("*"); } }