SpringBoot升级2.4.0所出现的问题:When allowCredentials is true, allowedOrigins cannot contain the specia

亦凉 2022-10-12 14:58 95阅读 0赞

SpringBoot升级2.4.0访问Swagger接口报错,没有返回信息,服务的警告代码如下

报错信息 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

在这里插入图片描述

解决办法:跨域配置报错,将.allowedOrigins替换成.allowedOriginPatterns即可。

修改前的跨域配置

  1. @Configuration
  2. public class WebMvcConfig implements WebMvcConfigurer {
  3. /** * 开启跨域 */
  4. @Override
  5. public void addCorsMappings(CorsRegistry registry) {
  6. // 设置允许跨域的路由
  7. registry.addMapping("/**")
  8. // 设置允许跨域请求的域名
  9. .allowedOrigins("*")
  10. // 是否允许证书(cookies)
  11. .allowCredentials(true)
  12. // 设置允许的方法
  13. .allowedMethods("*")
  14. // 跨域允许时间
  15. .maxAge(3600);
  16. }
  17. }

修改后的跨域配置

  1. @Configuration
  2. public class WebMvcConfig implements WebMvcConfigurer {
  3. /** * 开启跨域 */
  4. @Override
  5. public void addCorsMappings(CorsRegistry registry) {
  6. // 设置允许跨域的路由
  7. registry.addMapping("/**")
  8. // 设置允许跨域请求的域名
  9. .allowedOriginPatterns("*")
  10. // 是否允许证书(cookies)
  11. .allowCredentials(true)
  12. // 设置允许的方法
  13. .allowedMethods("*")
  14. // 跨域允许时间
  15. .maxAge(3600);
  16. }
  17. }

转载自:https://blog.csdn.net/jxysgzs/article/details/110818712
感谢博主的分享

发表评论

表情:
评论列表 (有 0 条评论,95人围观)

还没有评论,来说两句吧...

相关阅读