回顶部

springboot跨域访问

写一个WebMvc配置类重写addCorsMappings即可

 1 @Configuration
 2 public class MyMvcConfig implements WebMvcConfigurer {
 3     @Override
 4     public void addCorsMappings(CorsRegistry registry) {
 5         registry.addMapping("/**")
 6                 .allowedOrigins("*")
 7                 .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
 8                 .allowCredentials(true)
 9                 .maxAge(3600)
10                 .allowedHeaders("*");
11 
12     }
13 }

 

posted @ 2019-11-21 14:12  一生。  阅读(239)  评论(0编辑  收藏  举报