1.写个配置类CorsConfig (如果不行,可以不写此类,和springcloud的版本有关)
2. 配置 application.properties 方式
#--------gateway配置-------- #跨域配置 spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowedOrigins=* spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowedHeaders=* spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowedMethods=* spring.cloud.gateway.globalcors.corsConfigurations.[/**].allowCredentials=true
yaml 方式
spring: cloud: gateway: globalcors: corsConfigurations: '[/**]': allowCredentials: true allowedHeaders: '*' allowedMethods: '*' allowedOrigins: '*'