1、添加springboot跨域
@Configuration public class ResourcesConfig implements WebMvcConfigurer { /** * 跨域配置 */ @Override public void addCorsMappings(CorsRegistry registry) { //设置允许跨域的路径 registry.addMapping("/**") //设置允许跨域的请求域名 .allowedOriginPatterns("*") //是否允许cookie .allowCredentials(true) //允许请求的方式 .allowedMethods("GET","POST","DELETE","PUT") //设置请求跨域的header属性 .allowedHeaders("*") //允许跨域时间 .maxAge(3600); } }
2、添加spring security跨域。找到继承 WebSecurityConfigurerAdapter的类,有如图这个就可以了