@Configuration
public class CorsConfig {
private CorsConfiguration buildConfig(){
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*");//允许任何域名使用
corsConfiguration.addAllowedMethod("*");//允许任何方法
corsConfiguration.addAllowedHeader("*");//允许任何请求头
return corsConfiguration;
}
@Bean
public CorsFilter corsFilter(){
UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**",buildConfig());//对接口配置跨域设置
return new CorsFilter(urlBasedCorsConfigurationSource);
}
}
将此配置后 应该就不存在跨域问题了