首页  编辑  

SpringBoot允许跨域请求CORS

Tags: /Java/   Date Created:
 1 import org.springframework.web.servlet.config.annotation.CorsRegistry;
 2 import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 3 
 4 public class WebMvcConfig implements WebMvcConfigurer {
 5     /**
 6      * 允许 CORS 请求,允许跨域请求
 7      *
 8      * @param registry
 9      */
10     @Override
11     public void addCorsMappings(CorsRegistry registry) {
12         registry.addMapping("/**").allowedMethods("GET", "POST");
13     }
14 }