在一个下午+半个晚上的找bug之后,总算发现了这个问题所在。
首先是前端报错:
Access to XMLHttpRequest at 'http://localhost:9527/api/user/user/info' from origin 'http://localhost:9528' has been blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:9528, *', but only one is allowed.
大意是header里有了多个值。一般这种情况都是nginx和网关同时配置了跨域,去掉其一即可,但我的错不是这个。经过排查之后发现如果你是使用网关的跨域过滤器,那么其他模块的controller不能使用@CrossOrign注解,要不然就会重复修改header,导致多值错误
spring cloud gateway 跨域问题记录
最新推荐文章于 2023-08-11 09:15:10 发布
本文详细解析了一个常见的前端跨域问题,即在使用网关跨域过滤器时,若其他模块的controller使用了@CrossOrigin注解,会导致header出现多值错误。文章通过实际案例分享了解决这一问题的有效方法。
3398

被折叠的 条评论
为什么被折叠?



