@Configuration
public class CorsConfig {
//网关跨域配置
@Bean
public CorsWebFilter corsFilter() {
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true); //是否允许携带cookie
config.addAllowedOrigin("*"); //可接受的域,是一个具体域名或者*(代表任意域名)
config.addAllowedHeader("*"); //允许携带的头
config.addAllowedMethod("*"); //允许访问的方式
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", config);
return new CorsWebFilter(source);
}
}
09-09
661
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-03
2674
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)