mport org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.reactive.CorsWebFilter; import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource; import org.springframework.web.util.pattern.PathPatternParser; /** * 解决跨域的配置类 * * @author Alay * @date 2021-05-29 11:37 * @project Braineex */ @Configuration public class CoreOriginConfig { /** * Gateway 上配置 跨域问题 * * @return */ @Bean public CorsWebFilter coreWebFilter() { CorsConfiguration config = new CorsConfiguration(); // * 号表示匹配任意的 config.addAllowedMethod("*"); config.addAllowedOrigin("*"); config.addAllowedHeader("*"); PathPatternParser patternParser = new PathPatternParser(); UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(patternParser); // ** 代表所有 source.registerCorsConfiguration("/**", config); CorsWebFilter corsWebFilter = new CorsWebFilter(source); return corsWebFilter; } }标签:web,springboot,CorsWebFilter,配置,springframework,import,org,config,跨域 From: https://www.cnblogs.com/lvjinlin/p/18336524
原文:https://www.cnblogs.com/chxlay/p/15150587.html