写一个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 }