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

柔光的暖阳◎ 2022-09-14 06:27 253阅读 0赞
  1. 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.

翻译如下:

20201207145148417.png

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

修改前:

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

发表评论

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

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

相关阅读