SpringBoot 跨域问题 When allowCredentials is true...
项目场景:
项目使用minio作为分布式文件管理,由于minio代码是从git中下载,SpringBoot版本与原项目版本不一致
SpringBoot 2.1.6 到 2.5.14
并且minio作为一个通用类得与项目进行整合
问题描述
SpringBoot启动并且访问Controller时会导致产生下面的错误提示:
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版本的迭代,导致有些代码的使用发生了转变
解决方案:
将CorsConfig中的 .allowedOrigins("*") 替换成 .allowedOriginPatterns("*") 即可成功解决