问题:在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页面,错误完美解决。

 

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐