问题:
Springboot升级至2.4.0中出现的跨域问题。
分析:
Springboot2.3.5.RELEASE时,我们可以使用CorsWebFilter进行如下设置解决跨域问题。
public CorsWebFilter corsWebFilter() {
UrlBasedCorsConfigurationSource configurationSource = new UrlBasedCorsConfigurationSource(new PathPatternParser());
CorsConfiguration configuration = new CorsConfiguration();
// 配置跨域
configuration.setAllowCredentials(true);
configuration.addAllowedOrigin("*");
configuration.addAllowedHeader("*");
configuration.addAllowedMethod("*");
configurationSource.registerCorsConfiguration("/**", configuration);
return new CorsWebFilter(configurationSource)