content: package com.zzyl.config;
  
  import 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;
  
  @Configuration
  public class CorsConfig {
  
      @Bean
      public CorsWebFilter corsFilter() {
          CorsConfiguration config = new CorsConfiguration();
          //允许所有的方法
          config.addAllowedMethod("*");
          //运行所有的域进行请求
          config.addAllowedOrigin("*");
          //允许所有的请求头
          config.addAllowedHeader("*");
          UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
          source.registerCorsConfiguration("/**", config);//针对所有的请求都支持跨域
          return new CorsWebFilter(source);
      }
  }