@Configuration
public class CorsConfig {
@Bean
public FilterRegistrationBean getBean() {
System.out.println("进入跨域设置");
CorsConfiguration config = new CorsConfiguration();
config.setAllowedHeaders(Arrays.asList("*"));
config.setAllowedMethods(Arrays.asList("*"));
config.setAllowedOrigins(Arrays.asList("*"));
config.setExposedHeaders(Arrays.asList("token"));
UrlBasedCorsConfigurationSource configurationSource = new UrlBasedCorsConfigurationSource();
configurationSource.registerCorsConfiguration("/**", config);
CorsFilter corsFilter = new CorsFilter(configurationSource);
return new FilterRegistrationBean(corsFilter, new ServletRegistrationBean[0]);
}
}