关于后端跨域报错When allowCredentials is true, allowedOrigins cannot contain the special value “*“ ...

2022-06-25 09:19:19

一般解决方法是新增开启跨域的配置类:

@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("*");
            }
        }

但是添加了配置类后发现还是报错,后来发现原来是因为Controller层上存在如下注解:

@CrossOrigin(allowCredentials = "true", origins = "*", maxAge = -1)

把这个注解删除问题即可解决。

  • 作者:BloodyManicure
  • 原文链接:https://blog.csdn.net/BloodyManicure/article/details/123518019
    更新时间:2022-06-25 09:19:19