本文主要是介绍跨域配置报错: When allowCredentials is true, allowedOrigins cannot contain the special value “*“,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题:在SpringBoot工程中配置跨域请求,启动项目后访问swagger页面报错:
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.
经百度所得,这是SpringBoot升级2.4.0后所出现的问题,博主SpringBoot版本为2.6.*,果然没有逃过这个魔咒。
解决方案:
CrosConfig.class原配置:
根据问题描述:To allow credentials to a set of origins, list them explicitly or consider using "allowedOriginPatterns" instead,我们可以将allowedOrigins改为 allowedOriginPatterns试试看,修改后CrosConfig.class配置如下:
此时重启项目并访问swagger页面,错误完美解决。
这篇关于跨域配置报错: When allowCredentials is true, allowedOrigins cannot contain the special value “*“的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!