@Configurationpublic 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); 这个参数为必须的
原文地址:https://www.cnblogs.com/grace-newbee/p/11509942.html
时间: 2024-10-12 09:28:34