gateway处理跨域问题,有两种方式,一种是配置文件,另外一种是代码
配置文件
spring: cloud: gateway: globalcors: cors-configurations: '[/**]': allowCredentials: true allowedMethods: "*" allowedHeaders: "*"
代码
@Configuration public class CornConfig { @Bean public CorsWebFilter corsWebFilter(){ CorsConfiguration corsConfiguration = new CorsConfiguration(); corsConfiguration.addAllowedMethod("*"); corsConfiguration.addAllowedOrigin("*"); corsConfiguration.addAllowedHeader("*"); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser()); source.registerCorsConfiguration("/**",corsConfiguration); return new CorsWebFilter(source); } }
以上内容纯学习使用!
标签:跨域,corsConfiguration,springcloud,source,new,gateway,配置文件 From: https://www.cnblogs.com/qwg-/p/18436272