Background : Front-end and back-end separation projects, front-end vue, back-end springboot, cross-domain processing is set during local debugging, and the uuid back-end generated by the front-end cannot be obtained from the header.
Solution : The following is to allow cross-domain, setting corsConfiguration.addExposedHeader("uuid"); release the uuid parameter, so that the backend can get it.
@Configuration
public class CorsConfig {
private CorsConfiguration buildConfig() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*");
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addAllowedMethod("*");
corsConfiguration.setMaxAge(3600L);
corsConfiguration.setAllowCredentials(true);
return corsConfiguration;
}
@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration corsConfiguration = buildConfig();
corsConfiguration.addExposedHeader("uuid");
source.registerCorsConfiguration("/**", corsConfiguration);
return new CorsFilter(source);
}
}