增加配置類
CorsConfig.java
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.reactive.CorsWebFilter; import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource; /** * @author . */ @Configuration public class CorsConfig { @Bean public CorsWebFilter corsWebFilter(){ UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); CorsConfiguration corsConfiguration = new CorsConfiguration(); //1、配置跨域 //允許哪些頭進行跨域 corsConfiguration.addAllowedHeader("*"); //允許哪些請求方式進行跨域 corsConfiguration.addAllowedMethod("*"); //允許哪些請求來源進行跨域 corsConfiguration.addAllowedOrigin("*"); //是否允許攜帶cookie進行跨域,否則跨域請求會丟失cookie信息 corsConfiguration.setAllowCredentials(true); source.registerCorsConfiguration("/**",corsConfiguration); return new CorsWebFilter(source); } }
這樣yml配置文件就不在需要配置了
然后要把網關之后使用的服務的跨域去掉 如果配置了的話