content: package com.ld.poetry.config;
  
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.cors.CorsConfiguration;
  import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
  import org.springframework.web.filter.CorsFilter;
  
  import java.util.ArrayList;
  import java.util.List;
  
  
  @Configuration
  public class CorsConfig {
  
      @Bean
      public CorsFilter corsFilter() {
          UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
          CorsConfiguration config = new CorsConfiguration();
          // 是否允许请求带有验证信息
          config.setAllowCredentials(true);
          List<String> allowedOriginPatterns = new ArrayList<>();
          allowedOriginPatterns.add("*");
          config.setAllowedOriginPatterns(allowedOriginPatterns);
  
          config.addAllowedHeader("*");
          config.addAllowedMethod("*");
          source.registerCorsConfiguration("/**", config);
          return new CorsFilter(source);
      }
  }