***解决sringboot跨域访问,添加跨域类即可(spring-boot-start-web包)***

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**

  • Created by user on 2019/8/22.

  • 添加支持CORS跨域访问

  • /
    @Configuration
    public class corsConfiguration implements WebMvcConfigurer {

    @Override
    public void addCorsMappings(CorsRegistry registry) {

      registry
              .addMapping("/**")             //配置可以被跨域的路径,可以任意配置,可以具体到直接请求路径
              .allowedMethods("*")           //允许所有的请求方法访问该跨域资源服务器,如:POST、GET、PUT、DELETE等
              .allowedOrigins("*")           //允许所有的请求域名访问我们的跨域资源,可以固定单条或者多条内容
              .allowedHeaders("*");          //允许所有的请求header访问,可以自定义设置任意请求头信息

    }
    }