只需要在gateway的网关配置当中增加如下配置即可 ![](https://img.kancloud.cn/0d/dc/0ddc5457a356c9d603adf25453beaf4a_1567x896.png) ### ~~~ #解决前后端跨域问题 # 允许请求来源(老版本叫allowedOrigin) spring.cloud.gateway.globalcors.cors-configurations.[/**].allowedOriginPatterns=* # 允许携带的头信息 spring.cloud.gateway.globalcors.cors-configurations.[/**].allowedHeaders=* # 允许的请求方式 spring.cloud.gateway.globalcors.cors-configurations.[/**].allowedMethods=* # 是否允许携带cookie spring.cloud.gateway.globalcors.cors-configurations.[/**].allowCredentials=true # 跨域检测的有效期,会发起一个OPTION请求 spring.cloud.gateway.globalcors.cors-configurations.[/**].maxAge=3600 ~~~