springboot 跨域请求处理
再启动类里添加一下代码:
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*");
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addAllowedMethod("*");
corsConfiguration.addExposedHeader("x-auth-token");
corsConfiguration.addExposedHeader("x-total-count");
source.registerCorsConfiguration("/**", corsConfiguration); // 4
return new CorsFilter(source);
}
亲测有效