Spring Cloud Gateway跨域配置

版本:Greenwich.SR2 + 

1.官网配置

https://cloud.spring.io/spring-cloud-static/spring-cloud-gateway/2.2.1.RELEASE/reference/html/#cors-configuration

给个例子:

spring:
  cloud:
      gateway:
        globalcors:
           cors-configurations:
               '[/**]':
                  allowCredentials: true
                  allowedOrigins: "*"
                  allowedMethods: "*"
                  allowedHeaders: "*"

2.配置以后无效

查看响应信息

发现有多条

原因:

网关配置了跨域,服务里也配置了跨域。

解决办法:

去除服务里的配置

原文地址:https://www.cnblogs.com/tusheng/p/12256184.html