SpringBoot中跨域问题

项目中经常会遇到浏览器跨域的问题,解决方式在启动类中配置

@Bean
public FilterRegistrationBean corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("*");
config.addAllowedHeader("*");
config.addAllowedMethod("*");
source.registerCorsConfiguration("/**", config);
FilterRegistrationBean bean = new FilterRegistrationBean(new org.springframework.web.filter.CorsFilter(source));
bean.setOrder(0);
return bean;
}
上一篇:c# 单例模式[Singleton]之深夜闲聊


下一篇:在C#用HttpWebRequest中发送GET/HTTP/HTTPS请求【转载】