为了账号安全,请及时绑定邮箱和手机立即绑定

@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://img1.sycdn.imooc.com//611a64b50001691b19110697.jpg

正在回答

1 回答

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

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

@CrossOrigin(origins = "http://localhost:63342",allowCredentials = "true",allowedHeaders = "*")
@CrossOrigin(origins = {" * "}, allowedHeaders="*")
下载视频          
0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

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

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信