When allowCredentials is true, allowedOrigins cannot contain the special value “*“ since that cannot

最近新写springboot,配置跨域配置文件后出现的问题。

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: 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.
1
了解到在较新的springboot版本中,跨域配置需要将 .allowedOrigins 替换成 .allowedOriginPatterns

原配置:
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowCredentials(true)
.allowedMethods("GET", "POST", "DELETE", "PUT", "PATCH")
.maxAge(3600);
}

替换后:
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOriginPatterns("*")
.allowCredentials(true)
.allowedMethods("GET", "POST", "DELETE", "PUT", "PATCH")
.maxAge(3600);
}
————————————————
版权声明:本文为CSDN博主「想望着太阳」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_44540722/article/details/114021228

上一篇:electron使用electron-forge打包后报错cannot find module ‘XXX’


下一篇:错误记录【Operator ‘<‘ cannot be applied to ‘boolean‘, ‘int‘】