nginx + springboot2.4 跨域問(wèn)題崩掘,添加header、更改springmvc 配置方式少办,百度搜了一下午苞慢,快吐血了,都不行英妓。后來(lái)谷歌才改好的挽放,配置方式變了,需要用新的方式蔓纠,相當(dāng)于踩坑了
@Bean
public CorsFilter corsFilter() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
//1,允許任何來(lái)源
corsConfiguration.setAllowedOriginPatterns(Collections.singletonList("*"));
//2,允許任何請(qǐng)求頭
corsConfiguration.addAllowedHeader(CorsConfiguration.ALL);
//3,允許任何方法
corsConfiguration.addAllowedMethod(CorsConfiguration.ALL);
//4,允許憑證
corsConfiguration.setAllowCredentials(true);
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", corsConfiguration);
return new CorsFilter(source);
}
08.27更新 gateway上邊不好使 這個(gè)可以
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOriginPatterns("*")
.allowedMethods("*")
.maxAge(3600)
.allowCredentials(true);
}
}
-end-