springboot2 (跨域)

Spring Boot 2.0版本 全局配置跨域请求支持

//全局跨域配置
@Configuration
@EnableWebMvc
public class CorsConfig implements WebMvcConfigurer {
 @Override
 public void addCorsMappings(CorsRegistry registry) {
// 设置允许跨域的路径
registry.addMapping("/**")
    // 设置允许跨域请求的域名
    .allowedOrigins("*")
    // 是否允许证书 不再默认开启
    .allowCredentials(true)
    // 设置允许的方法
    .allowedMethods("*")
    // 跨域允许时间
    .maxAge(3600);
}
}

参考:https://blog.csdn.net/wangchengming1/article/details/82781557

你可能感兴趣的:(springboot2)