springboot集成shiro的权限中cors跨域问题

@Configuration
public class CorsConfig {
private CorsConfiguration buildConfig() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOrigin("*");
corsConfiguration.addAllowedHeader("*");
corsConfiguration.addAllowedMethod("*");
corsConfiguration.setMaxAge(3600L);
corsConfiguration.setAllowCredentials(true);
return corsConfiguration;
}

@Bean
public CorsFilter corsFilter() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", buildConfig());
return new CorsFilter(source);
}
}

//请求的最大时间
corsConfiguration.setMaxAge(3600L);     
// 是否支持安全证书
corsConfiguration.setAllowCredentials(true);

这个参数为必须的

上一篇:spingsecurity 前后端分离跨域,ajax无用户信息


下一篇:后端解决跨域问题