@Configuration
public class CorsAndJwtConfig {
private CorsConfiguration corsConfig() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.addAllowedOriginPattern("*"); //允许所有域名访问
corsConfiguration.addAllowedHeader("*"); //允许所有请求头
corsConfiguration.addAllowedMethod("*"); //允许所有的请求类型
corsConfiguration.setMaxAge(3600L);
corsConfiguration.setAllowCredentials(true); //允许请求携带验证信息(cookie)
return corsConfiguration;
}
@Bean
public CorsFilter corsFilter() {
//存储request与跨域配置信息的容器,基于url的映射
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", corsConfig());
return new CorsFilter(source);
}
}
java配置跨域配置
最新推荐文章于 2024-07-29 14:22:26 发布