Spring Cloud Gateway 处理跨域

        添加如下代码,即可处理跨域问题。

@Configuration
public class CorsConfig {
    @Bean
    public CorsWebFilter corsFilter() {
        CorsConfiguration config = new CorsConfiguration();
        config.addAllowedMethod("*");
        config.addAllowedOrigin("*");
        config.addAllowedHeader("*");

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
        source.registerCorsConfiguration("/**", config);

        return new CorsWebFilter(source);
    }
}

你可能感兴趣的:(后端功能,SpringCloud,网关,spring,gateway,spring,cloud,网关,跨域)