springcloud解决跨域问题
最好在网关中定义解决跨域问题,新建一个配置类,实现一个CorsFilter 就可以了
@Configuration public class GatewayCorsConfiguation { @Bean public CorsFilter corsFilter(){ // 初始化cors配置对象 CorsConfiguration configuration = new CorsConfiguration(); configuration.setAllowCredentials(true); // 允许使用cookie,但是使用cookie是addAllowedOrigin必须是具体的地址,不能是* // configuration.addAllowedOrigin("*"); configuration.addAllowedOrigin("http://manage.leyou.com"); configuration.addAllowedMethod("*"); //允许的请求方式,get,put,post,delete configuration.addAllowedHeader("*");//允许的头信息 //初始化cors的源对象配置 UrlBasedCorsConfigurationSource corsConfigurationSource = new UrlBasedCorsConfigurationSource(); corsConfigurationSource.registerCorsConfiguration("/**",configuration); //3.返回新的CorsFilter. return new CorsFilter(corsConfigurationSource); } }