报错
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.
源代码
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigin("*")
.allowedMethods("GET", "POST", "DELETE", "PUT", "PATCH")
.allowCredentials(true)
.maxAge(3600);
}
}
解决
按照提示,将allowedOrigin改为allowedOriginPatterns即可。
原因
Spring Boot 版本升级导致。