SpringBoot 允许跨域
解决办法
@SpringBootApplication
@MapperScan("com.humorchen.pastry_examination.mapper")
public class PastryExaminationApplication implements WebMvcConfigurer {
public static void main(String[] args) {
SpringApplication.run(PastryExaminationApplication.class, args);
}
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowCredentials(true)
.allowedHeaders("*")
.allowedOriginPatterns("*")
.allowedMethods("*");
}
}
新版本springboot跨域解决办法,把这个配置bean注入就可以了
@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedHeaders("*")
.allowedMethods("*")
.allowedOrigins("*")
.allowCredentials(true);
}
};
}
本文来自博客园,作者:HumorChen99,转载请注明原文链接:https://www.cnblogs.com/HumorChen/p/18039604