java.lang.IllegalArgumentException: When allowCredentials is true

java.lang.IllegalArgumentException: When allowCredentials is true_第1张图片 

1.遇到的错误

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.

 

2.解决办法 

因为调整了springboot-3.3.0版本,查了下需要修改参数allowedOriginPatterns。

@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
                .allowCredentials(true)
                .maxAge(3600)
                .allowedHeaders("*");
    }
}
 

你可能感兴趣的:(java,开发语言)