问答详情
源自:3-11 用户模型管理--用户注册功能实现02

@CrossOrigin(allowCredentials = "true",allowedHeaders = "*") 总是报错

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invocation of init method failed; nested exception is 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.

http://img.mukewang.com/611a64b50001691b19110697.jpg

提问者:慕粉0834181895 2021-08-16 21:16

个回答

  • weixin_慕UI9186130
    2022-08-14 21:32:19

    在最新的 2.5.2 版本中,使用这种方式运行项目会报错,使用了 allowCredentials = “true” 之后,不可以把origin设置为*(即默认状态)。

    如果在IDEA里运行可以加上域名否则就用第二行的

    @CrossOrigin(origins = "http://localhost:63342",allowCredentials = "true",allowedHeaders = "*")
    @CrossOrigin(origins = {" * "}, allowedHeaders="*")
    下载视频