解决跨域
package com.zzc.gateway.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.reactive.CorsConfigurationSource; import org.springframework.web.cors.reactive.CorsWebFilter; import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource; import org.springframework.web.filter.CorsFilter; import org.springframework.web.servlet.config.annotation.CorsRegistry; //解决跨域问题 @Configuration public class CrossConfig { @Bean public CorsWebFilter getCorsWebFilter() { //基于url跨域,选择reactive包下的 UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); //跨域配置信息 CorsConfiguration corsConfiguration = new CorsConfiguration(); //允许跨域的头 corsConfiguration.addAllowedHeader("*"); //允许跨域的请求方式 corsConfiguration.addAllowedMethod("*"); //允许跨域的请求来源 corsConfiguration.addAllowedOrigin("*"); //是否允许携带cookie跨域 corsConfiguration.setAllowCredentials(true); //所有请求都进行跨域配置 source.registerCorsConfiguration("/**",corsConfiguration); CorsWebFilter corsWebFilter = new CorsWebFilter(source); return corsWebFilter; } }