## SpringSecurity+jwt配置浏览器跨域(SpringBoot+SpringSecurity)
①先对SpringBoot配置,config/CorsConfig运行跨域请求
@Configuration
public class CorsConfig implements WebMvcConfigurer {
// 配置springboot跨域
@Override
public void addCorsMappings(CorsRegistry registry) {
// 设置允许跨域的路径
registry.addMapping("/**")
// 设置允许跨域请求的域名
.allowedOriginPatterns("*")
// 是否允许cookie
.allowCredentials(true)
// 设置允许的请求方式
.allowedMethods("GET", "POST", "DELETE", "PUT")
// 设置允许的header属性
.allowedHeaders("*")
// 跨域允许时间
.maxAge(3600);
}
}
②开启SpringSecurity的,config/SecurityConfig跨域访问
//允许跨域
http.cors();

浙公网安备 33010602011771号