Spring boot 遇到前端报错Access-Control-Allow-Origin 跨域问题

来源:互联网 发布:验证java安装成功 编辑:程序博客网 时间:2024/06/07 01:43

前端报错 Access-Control-Allow-Origin 的前端问题解决:

在spring boot 服务中心添加一个配置文件:

import org.springframework.context.annotation.Configuration;  import org.springframework.web.servlet.config.annotation.CorsRegistry;  import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;  @Configuration  public class CorsConfig extends WebMvcConfigurerAdapter {      @Override      public void addCorsMappings(CorsRegistry registry) {          registry.addMapping("/**")                  .allowedOrigins("*")                  .allowCredentials(true)                  .allowedMethods("GET", "POST", "DELETE", "PUT")                  .maxAge(3600);      }  }  



阅读全文
0 0
原创粉丝点击