其他分享
首页 > 其他分享> > When allowCredentials is true, allowedOrigins cannot contain the special value “*“ since that cannot

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

标签:since,When,allowCredentials,cannot,registry,true,allowedOriginPatterns,allowedOr
来源: https://www.cnblogs.com/telwanggs/p/15838143.html