AI智能
改变未来

When allowCredentials is true, allowedOrigins cannot contain the special value “*“

TOC

前言

  • 项目接口访问出现
    allowedOrigins cannot contain the special value "*"
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.

修改方式

  • 修改
    allowedOrigins

    allowedOriginPatterns
  • 修改前
@Overridepublic void addCorsMappings(CorsRegistry registry) {registry.addMapping("/**").allowedOrigins("*").allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS").allowCredentials(true).maxAge(3600).allowedHeaders("*");}
  • 修改后
@Overridepublic void addCorsMappings(CorsRegistry registry) {registry.addMapping("/**").allowedOriginPatterns("*").allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS").allowCredentials(true).maxAge(3600).allowedHeaders("*");}

– End -﹀﹀﹀梦想是咸鱼关注一下吧

赞(0) 打赏
未经允许不得转载:爱站程序员基地 » When allowCredentials is true, allowedOrigins cannot contain the special value “*“