问题:前端可以接收到请求但是无法获取自定义Header的token

解决
在SpringBoot中配置如下

@Configuration
public class CORSConfiguration implements WebMvcConfigurer {
@Bean
public CorsFilter corsFilter() {
final UrlBasedCorsConfigurationSource urlBasedCorsConfigurationSource = new UrlBasedCorsConfigurationSource();
final CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setAllowCredentials(true); /*是否允许请求带有验证信息*/
corsConfiguration.addAllowedOrigin("*");/*允许访问的客户端域名*/
corsConfiguration.addAllowedHeader("*");/*允许服务端访问的客户端请求头*/
corsConfiguration.addAllowedMethod("*"); /*允许访问的方法名,GET POST等*/
corsConfiguration.addExposedHeader("token");/*暴露哪些头部信息 不能用*因为跨域访问默认不能获取全部头部信息*/
corsConfiguration.addExposedHeader("Authorization");
urlBasedCorsConfigurationSource.registerCorsConfiguration("/**", corsConfiguration);
return new CorsFilter(urlBasedCorsConfigurationSource);
}
}